Exception while accessing Jersey REST webservice

2019-07-24 16:50发布

I am trying to get REST webservices working in my app. I am using jersey with Spring 2.5. The endpoints for the webservices are generated with enunciate 1.9. When I deploy the generated war file with Tomcat and access the REST webservice I get the following exception:

javax.servlet.ServletException: Servlet.init() for servlet jersey threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
java.lang.Thread.run(Thread.java:662)

root cause:

java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)V
com.sun.jersey.impl.container.config.AnnotatedClassScanner.analyzeClassFile(AnnotatedClassScanner.java:267)
com.sun.jersey.impl.container.config.AnnotatedClassScanner.indexJar(AnnotatedClassScanner.java:229)
com.sun.jersey.impl.container.config.AnnotatedClassScanner.indexJar(AnnotatedClassScanner.java:218)
com.sun.jersey.impl.container.config.AnnotatedClassScanner.indexDir(AnnotatedClassScanner.java:210)
com.sun.jersey.impl.container.config.AnnotatedClassScanner.index(AnnotatedClassScanner.java:169)
com.sun.jersey.impl.container.config.AnnotatedClassScanner.scan(AnnotatedClassScanner.java:105)
com.sun.jersey.api.core.ClasspathResourceConfig.init(ClasspathResourceConfig.java:131)
com.sun.jersey.api.core.ClasspathResourceConfig.<init>(ClasspathResourceConfig.java:103)
com.sun.jersey.api.core.ClasspathResourceConfig.<init>(ClasspathResourceConfig.java:85)
com.sun.jersey.spi.container.servlet.ServletContainer.createResourceConfig(ServletContainer.java:395)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:194)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
java.lang.Thread.run(Thread.java:662)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.

My web.xml for the REST servlet part looks like this:

<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.codehaus.enunciate.modules.jersey.EnunciateSpringServlet</servlet-class>
<init-param>
  <param-name>org.codehaus.enunciate.modules.jersey.config.ServletPath</param-name>
  <param-value>/rest</param-value>

</init-param>

Is there something I need to fix here in the configuration, that can fix the issue?

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-24 17:02

This could also be be because of duplicate jar in your build path . If you're using Maven , I suggest you do a dependency:tree to figure out if there are any duplicates . Also open up your .classpath file and check for build path issues.

查看更多
戒情不戒烟
3楼-- · 2019-07-24 17:05

java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)V com.sun.jersey.impl.container.config.AnnotatedClassScanner.analyzeClassFile(AnnotatedClassScanner.java:267)

does your asm in class path match Jersey need?

try to check it

查看更多
闹够了就滚
4楼-- · 2019-07-24 17:13

java.lang.NoSuchMethodError: happens when you have wrong version of class/Jar (could be newer version/older version) file in classpath. Make sure the jars you have in classpath are supported versions.

查看更多
登录 后发表回答