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

时间:2015-03-18 22:44:16

标签: java web-services rest maven tomcat

所有,我有一个REST项目来学习REST。以下是为Jersey和Javax提供jar的pom.xml。我使用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服务时,收到以下错误。

我谷歌搜索它,在大多数地方,它说这是一个maven依赖/冲突问题赌注。 Jersey和JAX-RS API罐子。我不知道罐子可能会发生冲突。

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

我无法弄清楚可能出现的问题...如果您有任何想法,请告诉我。非常感谢任何帮助。

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)

3 个答案:

答案 0 :(得分:2)

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

javaee-api 7.0

jar并添加:

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

上述例外消失了。为了保持一致性。泽西客户端和服务器罐,使用:

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共存。

答案 1 :(得分:0)

HI使用weblogic 10.3遇到了问题然后我刚刚删除了javax.ws jar及其依赖项,然后我的应用程序运行良好

答案 2 :(得分:0)

升级球衣1.17时我得到了这个 - &gt; 1.19。试过球衣2,但这些例子没有用。经过相当长的一段时间后,我将其降级为1.17。