[英]Jersey REST webservice subresources not found
At first in my web server I only had one REST servlet. 最初,在Web服务器中,我只有一个REST Servlet。 Something like: 就像是:
@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 {
...
}
...
}
And the web.xml: 和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>
But then I wanted to add some static html to the server, so I updated the servlet mapping to /rest/* 但是后来我想向服务器添加一些静态html,所以我将servlet映射更新为/ rest / *
and the @Path directive of Controller servlet class from "/" to "/rest". 以及Controller Servlet类的@Path指令从“ /”到“ / rest”。 Everything works fine but the sub-resources or methods of controller with the @path directive that stopped working.. ie: 一切正常,但是带有@path指令的控制器的子资源或方法已停止工作。即:
Any help? 有什么帮助吗? I already tried a list of combinations of / after and before each @Path directive, with no success... Many thanks 我已经尝试了每个@Path指令前后的/组合列表,但没有成功...非常感谢
One update: 一个更新:
I used the trace util and got the following results: 我使用了跟踪工具,并得到了以下结果:
for /[app-name]/rest (it works): 对于/ [app-name] / rest(有效):
for /[app-name]/rest/resource1 (it doesn't work): 对于/ [app-name] / rest / resource1(无效):
I hope it helps someone to help me.. 我希望它能帮助某人帮助我。
If you define your servlet mapping as /rest/*
, don't repeat /rest
in the @Path
annotation of your resources. 如果将servlet映射定义为/rest/*
,请不要在资源的@Path
注释中重复/rest
。 Ie all you need to do is keep the controller as is (in your question above) and just change the servlet mapping. 也就是说,您需要做的就是保持控制器不变(在上面的问题中),然后更改servlet映射。 The URL at which the resources are available is: 资源可用的URL是:
<application_context_path>/<servlet_mapping>
So, if you change the @Path
annotation from @Path("/")
to @Path("rest")
and you also change the servlet mapping to /rest
, then your resources would be available at: 因此,如果将@Path
注释从@Path("/")
更改为@Path("rest")
并且还将servlet映射更改为/rest
,则可以在以下位置获得资源:
<application_context_path>/rest/rest/*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.