一尘不染

java.lang.AbstractMethodError:javax.ws.rs.core.UriBuilder.uri(Ljava / lang /String;)Ljavax / ws / rs / core / UriBuilder;

tomcat

所有,我有一个小的REST项目来学习REST。以下是pom.xml,它为Jersey和Javax提供了jar。我使用Tomcat 8。

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.1.12</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>
</dependencies>

当我尝试运行任何Web服务时,都会出现以下错误。

我在Google上进行了搜索,在大多数地方,它都说这是行家依赖/冲突的问题。泽西岛和JAX-RS APIjar。我无法找出可能引起冲突的jar。

请注意,我运行这些服务没问题…当我更换笔记本电脑时开始收到此错误…升级到Tomcat 8,安装了仍在Java 7上的Eclipse Luna。

我不知道可能出了什么问题……如果您有任何想法,请告诉我。任何帮助是极大的赞赏。

exception

javax.servlet.ServletException: Servlet execution threw an exception
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

    : Servlet.service() for servlet [Jersey Servlet] in context with path            [/restfulAPI] 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:662)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

阅读 1299

收藏
2020-06-16

共1个答案

一尘不染

虽然我不知道为什么它曾经与Tomcat 6一起使用并在升级到Tomcat8时就开始给出上述异常,但是删除了:

javaee-api 7.0

jar并添加:

<dependency> 
    <groupId>javax.ws.rs</groupId> 
    <artifactId>jsr311-api</artifactId> 
    <version>1.1.1</version> 
</dependency>

上面的异常消失了。为了有一致性下注。泽西岛客户端和服务器jar,用于:

jersey-server 1.10

jar但收到此错误:

java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

当放置:

jersey-server 1.9

返回,异常消失了,REST服务再次开始工作。

请注意,如果您的应用程序需要javaee-api中的其他jar,请分别添加每个jar;看起来javaee-api程序包jar无法与Jersey 1共存。

2020-06-16