。在我的spring hibernate应用程序中获取java.lang.NoSuchMethodError:org.objectweb.asm.ClassWriter。<init>(Z)V </init>

时间:2013-10-11 10:17:41

标签: spring hibernate jersey tomcat7 gradle

我在我的应用程序中使用spring和hibernate。为了构建REST API,我使用了jersey,它是一个基于gradle的项目。这些是我在build.gradle中指定的依赖项:

compile 'org.springframework:spring-core:3.2.4.RELEASE',
       'org.springframework:spring-context:3.2.4.RELEASE',
       'org.springframework:spring-web:3.2.4.RELEASE',
       'com.sun.jersey:jersey-server:1.8',
       'com.sun.jersey:jersey-core:1.8',
       'mysql:mysql-connector-java:5.1.26',
       'c3p0:c3p0:0.9.1.2',
       'javax.transaction:jta:1.1',
       'org.hibernate:hibernate:3.2.5.GA',
       'org.hibernate:hibernate-annotations:3.3.1.GA',
       'asm:asm:3.1',
       'cglib:cglib-nodep:2.2',
       'org.springframework:spring-hibernate3:2.0.8',
       'org.hibernate:ejb3-persistence:1.0.2.GA'

即使我给出的hibernate版本是3.2.5,但是当我构建它时它正在下载3.2.6。当我将war部署到tomcat7时,我得到java.lang.NoSuchMethodError:org.objectweb.asm.ClassWriter。(Z)V。这是完整的堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/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:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
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:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:542)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1462)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1445)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:677)
at org.apache.catalina.manager.ManagerServlet.doPut(ManagerServlet.java:435)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
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.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 52 more

这是我的applicationContext.xml:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/my_db"/>
    <property name="user" value="coder"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property name="annotatedClasses">
        <list>
            <value>com.myprojects.pojos.AppConfig</value>
        </list>
    </property>
</bean>

我在许多地方发现它是由asm引起的,他们坚持使用asm-3.1我已经使用但我仍然得到同样的错误。无法缩小哪个库存在冲突。

AppConfig类:

package com.appdevapi.appconfig.pojos;

import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;

@Entity
@Table(name = "app_config")
public class AppConfig {

  @Id
  @Column(name = "id")
  private int id;
  @Column(name = "name")
  private String name;
  @Column(name = "description")
  private String description;
  @Column(name = "created_time")
  private Date createdTime;
  @Column(name = "updated_time")
  private Date updatedTime;

  public AppConfig(String name, String description) {
    this.name = name;
    this.description = description;
  }

  public AppConfig(String name) {
    this.name = name;
  }

  public AppConfig() {
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getDescription() {
    return description;
  }

  public Date getCreatedTime() {
    return createdTime;
  }

  public void setCreatedTime(Date createdTime) {
    this.createdTime = createdTime;
  }

  public Date getUpdatedTime() {
    return updatedTime;
  }

  public void setUpdatedTime(Date updatedTime) {
    this.updatedTime = updatedTime;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  @PrePersist
  public void assignCreatedTime() {
    Long curTimestamp = new java.util.Date().getTime();
    this.setCreatedTime(new Date(curTimestamp));
  }

  @PrePersist
  @PreUpdate
  public void assignUpdatedTime() {
    Long curTimestamp = new java.util.Date().getTime();
    this.setUpdatedTime(new Date(curTimestamp));
  }
}

依赖关系:

  • aopalliance-1.0
  • ANTLR-2.7.6
  • ASM-3.1
  • ASM-ATTRS-1.5.3
  • c3p0-0.9.1.2
  • CGLIB的2.1_3
  • 公共收集-2.1.1
  • 共享记录
  • DOM4J-1.6.1
  • ehcache的-1.2.3
  • ejb3-persistence-1.0.2.GA
  • 冬眠-3.2.6
  • hibernate-annotations-3.3.1.GA
  • 冬眠-公地注解-3.0.0
  • 球衣核-1.8
  • jerser - 服务器 - 1.8
  • JTA-1.1
  • MySQL的连接器的Java-5.1.26
  • 弹簧AOP-3.2.4.RELEASE
  • 弹簧3.2.4.RELEASE
  • 弹簧芯3.2.4.RELEASE
  • 弹簧表达-3.2.4.RELEASE
  • 弹簧JDBC-3.2.4.RELEASE
  • 弹簧ORM-3.2.4.RELEASE
  • 弹簧-TX-3.2.4.RELEASE
  • 弹簧网络3.2.4.RELEASE

4 个答案:

答案 0 :(得分:0)

请确保您拥有以下版本

        

    <pathelement location="${JAVA_LIB}/hibernate-3.2/lib/antlr-2.7.6.jar"/>
    <pathelement location="${JAVA_LIB}/hibernate-3.2/lib/asm.jar"/>
    <pathelement location="${JAVA_LIB}/hibernate-3.2/lib/cglib-nodep-2.1_3.jar"/>

    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-beans.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-context.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-core.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-mock.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-dao.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-jdbc.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-support.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/lib/aopalliance/aopalliance.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-aop.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring-remoting.jar" />
    <pathelement location="${JAVA_LIB}/spring-2.0.2/spring.jar" />
    <pathelement location="${JAVA_LIB}/spring-framework-2.0.6/spring-test.jar" />

答案 1 :(得分:0)

问题在于hibernate asm.jar。删除hibernate的当前依赖项并下载hibernate3.jar,asm.jar,Dom4j.jar并添加它

答案 2 :(得分:0)

谷歌两天后我得到了解决方案,只需删除所有asm.jar,asm-attr jar和cglib.jar,只添加 cglib-node 2.1_3.jar

答案 3 :(得分:0)

抛出

NoSuchMethodError主要是因为gradle或其他依赖管理工具脚本中指定的dependecies中的版本和版本不兼容。

因此,请花时间重新评估您的依赖关系,兼容性和版本。我相信这会解决它。

可在此处找到更详细的描述。 Docker Image of Jersey Web Application