[英]JAX-RS with Jersey 2.22.2 + Tomcat 7.0.59 : The requested resource is not available
I have built separated rest-model library and when the jersey do the resource config packages , seems doesn't work and it will response The requested resource is not available.我已经建立了独立的休息模型库,当球衣做资源配置包时,似乎不起作用,它会响应请求的资源不可用。
I have used : Jersey 2.22.2 and Tomcat 7.0.59我使用过: Jersey 2.22.2 和 Tomcat 7.0.59
And please find the following details below :请在下面找到以下详细信息:
rest-model.jar (file)
> com.company.rest.domain.* (package)
> TestData.class (file)
> @XmlRootElement
> class TestData {
> private String str ;
> public TestData() {}
> public TestData(String str) { setStr(str); }
> public String getStr() { return str ; }
> public void setStr(String str) { this.str = str ; }
> }
> com.company.rest.service.* (package)
> TestService.class (file)
> @Path("/test")
> @Produces({MediaType.APPLICATION_JSON})
> class TestService {
> @GET public TestData test() {
> return new TestData("test") ;
> }
> }
Tomcat with classpath to file rest-model.jar
WebRoot (folder)
> WEB-INF (folder)
> web.xml (file)
<servlet>
<servlet-name>RestApp</servlet-name>
<servlet-class>
org.glassfish.jersey.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<param-value>
com.company.rest.service
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RestApp</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
The init-param used for package scanning is wrong.用于包扫描的 init-param 错误。
For Jersey 2.XX, you need to configure it as:对于 Jersey 2.XX,您需要将其配置为:
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.company.rest.service</param-value>
</init-param>
If you navigate to your tomcat folder, specifically the configuration file conf/server.xml, does the tag in the bottom look as you expect?如果您导航到您的 tomcat 文件夹,特别是配置文件 conf/server.xml,底部的标签是否如您所愿? It might be that you are simply requesting the wrong URL (missing a base path) - see what the server.xml file tells you about the path to your web app.
可能是您只是请求了错误的 URL(缺少基本路径) - 查看 server.xml 文件告诉您有关 Web 应用程序路径的内容。
In Eclipse, you will have server pane with two sub panes: Overview and Modules.在 Eclipse 中,您将拥有带有两个子窗格的服务器窗格:概览和模块。 The modules shows your web app, and the base paths.
这些模块显示了您的 Web 应用程序和基本路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.