gradle .获取java.lang.NoSuchMethodError:在< init>我的Spring休眠应用程序中使用(Z)V

fafcakar  于 2022-12-29  发布在  Java
关注(0)|答案(4)|浏览(264)

我在我的应用中使用了spring和hib。对于构建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'

尽管我给出的hib版本是3.2.5,但我构建时它正在下载3.2.6,当我将war部署到tomcat7时,我得到了java.lang.NoSuchMethodError:(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版本
  • 抗肿瘤药-2.7.6
  • 美国标准协会-3.1
  • 美国标准协会-原子吸收光谱-1.5.3
  • 三磷酸腺苷-0.9.1.2
  • cglib-2.1_3
  • 公用-收集-2.1.1
  • 公用记录
  • 第4j部分-1.6.1节
  • 电子高速缓存-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
  • 联合技术援助-1.1
  • mysql-connector-java-5.1.26
  • spring-aop-3.2.4.RELEASE
  • spring-3.2.4.RELEASE
  • spring-core-3.2.4.RELEASE
  • spring-expression-3.2.4.RELEASE
  • spring-jdbc-3.2.4.RELEASE
  • spring-orm-3.2.4.RELEASE
  • spring-tx-3.2.4.RELEASE
  • spring-web-3.2.4.RELEASE
yrwegjxp

yrwegjxp1#

抛出NoSuchMethodError的主要原因是,在gradle或其他依赖关系管理工具的脚本中指定的依赖关系中存在不兼容的版本和版本不匹配。
所以,花点时间重新评估你的依赖性、兼容性和版本。我相信这会解决问题。
更详细的描述可以在这里找到。Jersey Web应用程序的Docker图像

olhwl3o2

olhwl3o22#

请确保您具有以下版本

<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" />
hxzsmxv2

hxzsmxv23#

问题出在hibasm.jar上。请删除当前对hib的依赖关系,然后下载hibernate3.jar、asm.jar、Dom4j.jar并添加它

fslejnso

fslejnso4#

经过两天的谷歌搜索,我得到了它的解决方案,只是删除所有的asm.jar,asm-attr jar和cglib.jar,只添加cglib-node 2.1_3.jar

相关问题