使用Jersey ContainerRequestFilter时获取root. cause java.lang.AbstractMethodError

时间:2013-11-29 13:08:00

标签: java maven tomcat jersey

INFO: Server startup in 6705 ms
Nov 29, 2013 6:17:38 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [JerseyServlet] in context with path [/jersey_project] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
    at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:649)
    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.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:472)
    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:947)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    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:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

3 个答案:

答案 0 :(得分:14)

您似乎正在使用Jersey 1.x(JAX-RS 1.1实现)和JAX-RS 2.0 API。在您的应用程序中,切换到Jersey 2(推荐)或用JAX-RS 1.1 API jar替换JAX-RS 2.0 API jar(它已经是jersey-common的一部分,因此删除2.0 API应该足够了。)

答案 1 :(得分:6)

你有maven依赖问题,删除所有依赖项,特别是容器jersey依赖项并添加这些:

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.1</version>
</dependency>

答案 2 :(得分:0)

我需要针对该问题的更具体答案,因此我向maven添加了以下插件:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>3.0.0-M3</version>
  <executions>
    <execution>
      <id>enforce</id>
      <configuration>
        <rules>
          <dependencyConvergence/>
        </rules>
      </configuration>
      <goals>
        <goal>enforce</goal>
      </goals>
    </execution>
  </executions>
</plugin>

上面显示了我所有的依赖项冲突,因此我设法解决了上述问题之外的更多问题,并使我的依赖关系树保持整洁。

该插件在调用时运行:

mvn clean install

并向您显示以下警告:

[WARNING] 
Dependency convergence error for com.fasterxml.jackson.core:jackson-core:2.8.10 paths to dependency are:
+-com.omilia:partners:5.4.0-RC-3
  +-org.glassfish.jersey.media:jersey-media-json-jackson:2.27
    +-com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.8.10
      +-com.fasterxml.jackson.core:jackson-core:2.8.10
and
+-com.omilia:partners:5.4.0-RC-3
  +-com.fasterxml.jackson.core:jackson-databind:2.9.6
    +-com.fasterxml.jackson.core:jackson-core:2.9.6

随后,当在pom中引用依赖项时,您可以排除特定的程序包:

<exclusion>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
</exclusion>

更多信息可以在这里找到:

Dependency Convergence Maven Documentation