Jersey、Guice 使用非根请求路径
我在标准配置的 Tomcat 6.0.32 上使用 Jersey 1.11 而不是 Guice 3.0:
configureServlets() {
filter("/ws/*").through(GuiceContainer.class);
}
和一个简单的资源类:
@Path("/resource")
public class Resource { ... }
鉴于此,我认为访问“/ws/resource”会起作用;但实际上并没有找到资源。问题似乎在于请求路径计算不正确。作为解决方法,我将参数 PROPERTY_FILTER_CONTEXT_PATH
设置为 /ws
,这使得整个事情正常工作:
Map<String, String> jerseyConfig = new HashMap<String, String>();
jerseyConfig.put(ServletContainer.PROPERTY_FILTER_CONTEXT_PATH, "/ws");
filter("/ws/*").through(GuiceContainer.class, jerseyConfig);
因此我的问题是:
- 这真的是一个错误还是一个“功能”?
- 有其他解决方案或解决方法吗?
作为信息,我看到了一个可能相关的 Guice 错误,它似乎已合并到另一个错误中,但我想知道它是否已正确修复(链接)
I'm using Jersey 1.11 over Guice 3.0 on Tomcat 6.0.32 in a standard configuration:
configureServlets() {
filter("/ws/*").through(GuiceContainer.class);
}
And a simple resource class:
@Path("/resource")
public class Resource { ... }
Given that, I would suppose that accessing "/ws/resource" would work; but actually no resources are found. The problem seems to lie in the request path not being computed correctly. As a workaround I have set the parameter PROPERTY_FILTER_CONTEXT_PATH
to /ws
, which make the whole thing work:
Map<String, String> jerseyConfig = new HashMap<String, String>();
jerseyConfig.put(ServletContainer.PROPERTY_FILTER_CONTEXT_PATH, "/ws");
filter("/ws/*").through(GuiceContainer.class, jerseyConfig);
Thus my questions are:
- Is this really a bug or a "feature" ?
- Is there another solution or workaround for this?
For info, I've seen one Guice bug that can be related, it seems to have been merged in another one but I'm wondering if it's properly fixed (link)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用服务而不是过滤器。
然后您就可以点击/ws/resource。
Use serve instead of filter.
You will then be able to hit /ws/resource.