[英]Jersey REST webservice subresources not found
最初,在Web服務器中,我只有一個REST Servlet。 就像是:
@Path("/")
public class Controller {
@GET
@Produces({ MediaType.TEXT_HTML })
public Response get(@Context UriInfo info) throws Exception {
...
}
@GET
@Path("resource1")
@Produces({ MediaType.TEXT_HTML })
public Response resource1() throws Exception {
...
}
...
}
和web.xml:
<servlet>
<servlet-name>rest</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>xpto.mypack1;xpto.mypack2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
但是后來我想向服務器添加一些靜態html,所以我將servlet映射更新為/ rest / *
以及Controller Servlet類的@Path指令從“ /”到“ / rest”。 一切正常,但是帶有@path指令的控制器的子資源或方法已停止工作。即:
有什么幫助嗎? 我已經嘗試了每個@Path指令前后的/組合列表,但沒有成功...非常感謝
一個更新:
我使用了跟蹤工具,並得到了以下結果:
對於/ [app-name] / rest(有效):
對於/ [app-name] / rest / resource1(無效):
我希望它能幫助某人幫助我。
如果將servlet映射定義為/rest/*
,請不要在資源的@Path
注釋中重復/rest
。 也就是說,您需要做的就是保持控制器不變(在上面的問題中),然后更改servlet映射。 資源可用的URL是:
<application_context_path>/<servlet_mapping>
因此,如果將@Path
注釋從@Path("/")
更改為@Path("rest")
並且還將servlet映射更改為/rest
,則可以在以下位置獲得資源:
<application_context_path>/rest/rest/*
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.