Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V的解決辦法__web

來源:互聯網
上載者:User

最近項目一直報

Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
這個錯誤,網上找了一些解決辦法,但是沒起作用。後來又在其他地方找到了篇文章,發現效果不錯,這裡分享一下解決辦法。

首先,錯誤如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)    at java.security.AccessController.doPrivileged(Native Method)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)    at java.util.concurrent.FutureTask.run(FutureTask.java:138)    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)    at java.lang.Thread.run(Thread.java:619)Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V    at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)    at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)    at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)    ... 29 more2015-5-21 16:44:08 org.apache.catalina.core.StandardContext listenerStart嚴重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)    at java.security.AccessController.doPrivileged(Native Method)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)    at java.util.concurrent.FutureTask.run(FutureTask.java:138)    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)    at java.lang.Thread.run(Thread.java:619)Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V    at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)    at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)    at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)    at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)    at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)    at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)    at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)    at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)    ... 29 more

解決辦法:

在使用Spring的AOP編程時,會用到這幾個lib:   asm-2.2.3.jar   asm-commons-2.2.3.jar   asm-util-2.2.3.jar   Hibernate使用如果lib:   asm.jar   asm-attrs.jar   其中asm-2.2.3.jar與asm.jar存在類上的衝突。。。   使用其中之一或兩者都使用,可能會出現如下錯誤:   java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor   java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor   java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit。。。。。。   解決辦法是:      1.去掉類路徑上的關於Hibernate的3個lib   asm.jar   asm-attrs.jar   cglib-2.1.3.jar   2.留著Spring中的以下4個lib   asm-2.2.3.jar   asm-commons-2.2.3.jar   asm-util-2.2.3.jar   cglib-nodep-2.1_3.jar   另一種解決方案  
去掉Spring中的asm-2.2.3.jar 
這裡,我使用的是的二種方法:直接刪掉spring中的asm.jar,然後項目就順利啟動了。終於解決了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.