我的 Tomcat 服务器不是 100% 像其他服务器,我正在尝试按照本教程进行操作:
http://www.suryasuravarapu.com/2009/02/rest-jersey-configuration-on-tomcat.html
到目前为止我已经下载了:
asm-3.3.1.jar
jersey-client-1.17.jar
jersey-core-1.17.jar
jersey-server-1.17.jar
并将它们放在我的/lib/目录中。
我的文件夹结构是这样的:
/WEB-INF/classes/rest/com/mkyong/HellowWorldService.class
我将我的 web.xml 定义为:
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mkyong.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/servlets/servlet/rest/*</url-pattern>
</servlet-mapping>
我不确定网址格式是否正确?
当我访问 myserver.com/servlets/servlet/rest/hello/Eric
时,我应该让它说 Jersey say: Eric 但我却收到 HTTP Status 500 错误:
Tomcat 日志说:
Feb 19, 2013 4:46:21 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
com.mkyong.rest
Feb 19, 2013 4:46:21 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.17 01/17/2013 04:27 PM'
Feb 19, 2013 4:46:21 PM com.sun.jersey.server.impl.application.RootResourceUriRules <init>
SEVERE: The ResourceConfig instance does not contain any root resource classes.
Feb 19, 2013 4:46:27 PM com.sun.jersey.api.core.PackagesResourceConfig init
大大收到任何帮助!
编辑:
我找到了 this article在男生页面上。但这没有多大意义。
最佳答案
对应本教程http://www.vogella.com/articles/REST/article.html#installation ,
This name is derived from the "display-name" defined in the web.xml file, augmented with the servlet-mapping url-pattern and the "hello" @Path annotation from your class file.
根据这个,在你的情况下,你的 web.xml
中的 display-name
有 ""
并且在链接中没有提到您用于测试。
编辑: 这个 servlet 的基本 URL 是:
http://your_domain:port/display-name/url-pattern/path_from_rest_class
关于java - 在我奇怪的 Tomcat 服务器上获取 RESTful Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14963110/