Jersey REST Service Error
来源:互联网 发布:有意境的网名知乎 编辑:程序博客网 时间:2024/06/05 17:20
當用Jersey時遇上 HTTP Status 500 - Servlet.init() for servlet Jersey REST Service threw exception, 有機會是出於 JAX-RS 1 and JAX-RS 2 jar 都在參考位置, 要在pom.xml 加一些排除。
HTTP Status 500 - Servlet.init() for servlet Jersey REST Service threw exception
type Exception report
message Servlet.init() for servlet Jersey REST Service threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exceptionorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)java.lang.Thread.run(Thread.java:745)
root cause
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:331)org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392)org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)javax.servlet.GenericServlet.init(GenericServlet.java:158)org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)java.lang.Thread.run(Thread.java:745)
Note: Please see above comments for further discussion and tips.
This error usual means that you have a both a JAX-RS 1 and JAX-RS 2 jar on the classpath. Jersey 2 uses JAX-RS 2 (javax.ws.rs-api-2.0.1.jar
), but if you have the jsr311-api.jar
also, which is JAX-RS 1, there is a javax.ws.rs.core.Application
in each jar. But the jsr311-api
Application
doesn't have the method getProperties()
(hence NoSuchMethodError
).
I've come to the conclusion that all you need to do is add the above exclusion to the swagger dependency. The Jackson 2.0 provider (which depends on JAX-RS 1) seems to be overridden by a 2.4.1 provider (which uses the new version). So we don't need to add it ourselves. When it's overridden, it seems to leave behind the jsr311-api.jar
. So if we exclude it, no one can attempt to use it, which looks to be the current problem
<dependency> <groupId>com.wordnik</groupId> <artifactId>swagger-core_2.10</artifactId> <version>1.3.11</version> <exclusions> <exclusion> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> </exclusion> </exclusions></dependency>
將上面整段加入pom.xml 的 Dependencies 內就可解決。- Jersey REST Service Error
- Jersey 实现Rest service
- rest web service - jersey . spring3
- Eclipse+Tomcat+Jersey 编写 REST web service
- Jersey : Java规范下REST风格Web Service开发框架
- Maven和Jersey Framework开发REST风格Web Service
- Maven和Jersey Framework开发REST风格Web Service
- 使用Maven和Jersey Framework开发REST风格Web Service
- Jersey make REST call
- [REST Jersey] @QueryParam Demo
- jersey实现rest实例
- Jersey VS Django-Rest
- Jersey REST Spring集成
- Jersey开发rest服务
- jersey搭建rest服务
- Jersey—— 一个基于Rest风格的Web Service开发框架
- jersey rest+spring 以及rest的简介
- 使用Jersey搭建REST问题
- JDK官方网站下载、安装教程及环境配置
- POJ1365——Prime Land(素数筛选加暴力)
- 单链表的翻转
- C loop
- 移动物体监控系统
- Jersey REST Service Error
- 什么是APT
- js获取浏览器滚动条距离顶端的距离
- 一北大毕业生的返乡报告:家乡面目全非 备感无力
- 欢迎使用CSDN-markdown编辑器
- Java 可执行Jar包打包方法
- 网站集成QQ登录功能
- MySQL数据库 表的基本操作
- Webservice接口开发,Spring注入失败