Jersey + Hibernate = NoSuchMethodError:org.objectweb.asm.ClassReader.accept(Lorg / objectweb / asm / ClassVisitor

时间:2011-10-11 05:45:53

标签: java hibernate spring maven jersey

(原帖) 将hibernate依赖项添加到pom.xml

时出现错误
2011-10-11 10:36:53.710::WARN:  failed guiceFilter
java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)V
     at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:133)
     at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86)
     at com.sun.jersey.core.util.Closing.f(Closing.java:71)
     at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:83)
     at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:80)
     at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:80)
     at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scan(FileSchemeScanner.java:71)
     at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:223)
     at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139)
     at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80)
     at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
     at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
     at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
     at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700)
     at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678)
     at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
     at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
     at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
     at javax.servlet.GenericServlet.init(GenericServlet.java:241)
     at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:117)
     at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82)
     at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:102)
     at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172)
     at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:589)
     at org.mortbay.jetty.servlet.Context.startContext(Context.java:139)
     at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
     at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:510)
     at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
     at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:110)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
     at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
     at org.mortbay.jetty.Server.doStart(Server.java:222)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
     at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:357)
     at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:293)
     at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:203)
     at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
     at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
     at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
     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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

(编辑)这也发生在我身上:Maven 2.2.1,这里依赖:树输出:

[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.knowledgefactor.amplifire.test.load.reports:ReportService:jar:1.0-SNAPSHOT
[INFO] +- org.springframework:spring-core:jar:3.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-context:jar:3.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.0.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:3.0.5.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-orm:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:2.5.6:compile
[INFO] +- org.springframework.batch:spring-batch-core:jar:2.1.8.RELEASE:compile
[INFO] |  +- org.springframework.batch:spring-batch-infrastructure:jar:2.1.8.RELEASE:compile
[INFO] |  +- com.thoughtworks.xstream:xstream:jar:1.3:compile
[INFO] |  |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] |  \- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] +- org.springframework:spring-web:jar:3.0.5.RELEASE:compile
[INFO] +- org.hibernate:hibernate:jar:3.2.7.ga:compile
[INFO] |  +- net.sf.ehcache:ehcache:jar:1.2.3:compile
[INFO] |  +- asm:asm-attrs:jar:1.5.3:compile

(编辑)我正在添加这么多文本,以便提供足够的上下文,以便编辑变得有效。

2 个答案:

答案 0 :(得分:7)

这意味着您的类路径上的asm.jar版本不正确。确保:

  • 您部署的lib文件夹包含与target / app.war / WEB-INF / lib
  • 相同的jar文件
  • 你没有两个版本的asm.jar
  • maven中没有冲突的版本

答案 1 :(得分:1)

线程已经过时了很多次,但是有人偶然发现了这个问题:

http://mathieuhicauber-java.blogspot.fr/2012/12/jax-rs-jersey-on-was-61-asm-classreader.html

基本上,Jersey加载和hibernate都需要asm jar,但是在两个不兼容的版本中。 您需要从hibernate依赖项中排除cglib(可传递地加载asm),并将cglib-nodep与其重新打包的asm类包含在内。