错误:java.lang.NoSuchMethodError:org.objectweb.asm.ClassWriter.<init>(I)V
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2432471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error : java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
提问by Hitesh Solanki
I am developing a small Spring application. I have to store the details of the student information in the database. I have developed one SimpleFormController. I have used NetBeans + Hibernate mapping + Spring. When I deploy the project, the following errors occurs.
我正在开发一个小的 Spring 应用程序。我必须将学生信息的详细信息存储在数据库中。我开发了一个 SimpleFormController。我使用过 NetBeans + Hibernate 映射 + Spring。当我部署项目时,出现以下错误。
My spring-config-db-applicationContext.xml is shown below:
我的 spring-config-db-applicationContext.xml 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Hibernate session factory -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<constructor-arg index="0">
<value>${driverClassName}</value>
</constructor-arg>
<constructor-arg index="1">
<value>${url}</value>
</constructor-arg>
<constructor-arg index="2">
<value>${username}</value>
</constructor-arg>
<constructor-arg index="3">
<value>${password}</value>
</constructor-arg>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<!-- <property name="configLocation">
<value>WEB-INF/classes/hibernate.cfg.xml</value>
</property> -->
<property name="mappingResources" >
<list>
<value>hibernate.cfg.xml</value>
</list>
</property>
<!-- <property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property> -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
Following error is occurs:
出现以下错误:
ERROR (org.springframework.web.context.ContextLoader:213) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [jndi:/localhost/Student/WEB-INF/classes/config/spring-db-applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1395)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:289)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:526)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:730)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:387)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:270)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:627)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:511)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1471)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:824)
at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:350)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:196)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)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:144)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
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:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:238)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1304)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:813)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:731)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1454)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1392)
... 48 more
Mar 12, 2010 5:32:28 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
采纳答案by Pascal Thivent
You have an incompatibility between the version of ASM required by Hibernate (asm-1.5.3.jar) and the one required by Spring. But, actually, I wonder why you have asm-2.2.3.jar on your classpath (ASM is bundled in spring.jar and spring-core.jar to avoid such problems AFAIK). See HHH-2222.
您在 Hibernate ( asm-1.5.3.jar)所需的 ASM 版本与Spring所需的版本之间存在不兼容。但是,实际上,我想知道为什么您的类路径上有 asm-2.2.3.jar(ASM 捆绑在 spring.jar 和 spring-core.jar 中以避免此类问题 AFAIK)。见HHH-2222。
回答by Stephen C
The NoSuchMethodErrorjavadoc says this:
该的NoSuchMethodErrorjavadoc中这样说:
Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
如果应用程序尝试调用类(静态或实例)的指定方法,并且该类不再具有该方法的定义,则抛出。
通常,这个错误是由编译器捕获的;如果类的定义发生了不兼容的更改,则此错误只会在运行时发生。
In your case, this Error is a strong indicationthat your webapp is using the wrong version of the JAR defining the org.objectweb.asm.*
classes.
在您的情况下,此错误强烈表明您的 web 应用程序使用了错误版本的 JAR 定义org.objectweb.asm.*
类。
回答by Narendra Choyal
I change my APIs as * cglib--- to ---> cglib-nodep-2.2.jar * cglib-asm--- to ---> cglib-asm.jar (i.e. latest one )
我将我的 API 更改为 * cglib--- 到 ---> cglib-nodep-2.2.jar * cglib-asm--- 到 ---> cglib-asm.jar(即最新的一个)
回答by Rob Hufschmitt
I found the solution to this problem here: http://www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html
我在这里找到了这个问题的解决方案:http: //www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html
回答by Jason
I had the same error when initializing Spring on startup, using some different library versions, but everything worked when I got my versions in this order in the classpath (the other libraries in the cp were not important):
我在启动时使用一些不同的库版本初始化 Spring 时遇到了同样的错误,但是当我在类路径中按此顺序获取我的版本时,一切正常(cp 中的其他库并不重要):
- asm-3.1.jar
- cglib-nodep-2.1_3.jar
- asm-attrs-1.5.3.jar
- asm-3.1.jar
- cglib-nodep-2.1_3.jar
- asm-attrs-1.5.3.jar
回答by Suganthan Madhavan Pillai
Update your pom.xml
更新你的 pom.xml
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
</dependency>
回答by BERGUIGA Mohamed Amine
to resolve this kind of problem you should add two jar in your dependency POM (if use Maven)
要解决此类问题,您应该在依赖项 POM 中添加两个 jar(如果使用 Maven)
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.1</version>
</dependency>
回答by Jim W
There is a lot of incompatibility between different versions of cglib and lots of poor advice that can be googled on this subject (use ancient versions of cglib-nodeb, etc). After wrestling with this nonsense for 3 days with an ancient version of Spring (2.5.6)I have discovered:
不同版本的 cglib 之间存在很多不兼容性,并且可以在 google 上搜索到很多关于这个主题的糟糕建议(使用 cglib-nodeb 的旧版本等)。在使用古老版本的 Spring (2.5.6) 与这些废话搏斗 3 天后,我发现:
- if Spring is throwing exceptions about NoSuchMethodError based on Enhancer from cglib missing setInterceptDuringConstruction(boolean), check your dependencies in maven (Dependency Hierarchy tab should list all the versions of cglib your project is polluted by). You probably have a dependency that is bringing in a pre-2.2 version of cglib, which Spring Cglib2AopProxy will grab Enhancer from to do the proxying. Add 2.2+ version to your dependencies but make sure to put in exclusions for these other versions. If you don't it will just keep blowing up.
- Make sure you have a high enough version of cglib in the current project's maven dependencies butbeware of picking too high a version because then you'll get IncompatibleClassChangeError(s) instead.
- Verify that your pom changes have made it into the project correctly by doing a maven update on the project in question and then looking at Project > preferences > Java Build Path > Libraries > Maven Dependencies. If you see the wrong cglib versions in there, time to edit the pom again.
- 如果 Spring 基于增强器从 cglib 中抛出有关 NoSuchMethodError 的异常缺少 setInterceptDuringConstruction(boolean),请检查您在 maven 中的依赖项(Dependency Hierarchy 选项卡应列出您的项目受到污染的 cglib 的所有版本)。您可能有一个依赖项,它引入了 2.2 之前版本的 cglib,Spring Cglib2AopProxy 将从中获取 Enhancer 来进行代理。将 2.2+ 版本添加到您的依赖项,但请确保为这些其他版本添加排除项。如果你不这样做,它只会继续爆炸。
- 确保在当前项目的 maven 依赖项中有足够高的 cglib 版本,但要小心选择太高的版本,因为那样你会得到 IncompatibleClassChangeError(s) 。
- 通过对有问题的项目进行 maven 更新,然后查看项目 > 首选项 > Java 构建路径 > 库 > Maven 依赖项,验证您的 pom 更改是否已正确进入项目。如果您在那里看到错误的 cglib 版本,请再次编辑 pom。
回答by toshi
I encountered the same error when added http-builder to dependencies.
In my case, I could solve by simply excluding asm like this:
将 http-builder 添加到依赖项时遇到了同样的错误。
就我而言,我可以通过简单地像这样排除 asm 来解决:
compile('org.codehaus.groovy.modules.http-builder:http-builder:0.7'){
excludes 'xml-apis'
exclude(group:'xerces', module: 'xercesImpl')
excludes 'asm'
}