泽西岛,吉斯使用非根请求路径 [英] Jersey, Guice using non-root request paths

查看:109
本文介绍了泽西岛,吉斯使用非根请求路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在标准配置下,我正在Tomcat 6.0.32上的Guice 3.0上使用Jersey 1.11:

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 { ... }

鉴于此,我假设访问"/ws/resource"将起作用;但实际上找不到资源.问题似乎在于请求路径未正确计算.作为解决方法,我将参数PROPERTY_FILTER_CONTEXT_PATH设置为/ws,这使整个工作正常进行:

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);

因此,我的问题是:

  1. 这真的是错误还是功能"?
  2. 是否有其他解决方案或解决方法?

有关信息,我已经看到一个可能与Guice相关的错误,它似乎已经合并到另一个bug中,但是我想知道它是否已正确修复(

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)

推荐答案

使用服务而不是过滤器.

Use serve instead of filter.

configureServlets() {
    serve("/ws/*").with(GuiceContainer.class);
}

您将可以访问/ws/resource.

You will then be able to hit /ws/resource.

这篇关于泽西岛,吉斯使用非根请求路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆