gpt4 book ai didi

spring - 在我的 Spring Hibernate 应用程序中获取 java.lang.NoSuchMethodError : org. objectweb.asm.ClassWriter.(Z)V

转载 作者:行者123 更新时间:2023-12-03 00:54:07 24 4
gpt4 key购买 nike

我在我的应用程序中使用 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
  • commons-collection-2.1.1
  • 公共(public)日志记录
  • dom4j-1.6.1
  • ehcache-1.2.3
  • ejb3-persistence-1.0.2.GA
  • hibernate-3.2.6
  • hibernate-annotations-3.3.1.GA
  • hibernate-commons-annotations-3.0.0
  • Jersey 核心-1.8
  • jerser-server-1.8
  • jta-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

最佳答案

请确保您有以下版本

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

关于spring - 在我的 Spring Hibernate 应用程序中获取 java.lang.NoSuchMethodError : org. objectweb.asm.ClassWriter.<init>(Z)V,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19315696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com