泽西+吉塞斯不能将非球衣资源与球衣资源混在一起

时间:2012-03-04 16:11:04

标签: java jersey guice

我怎样才能将非球衣资源与球衣资源一起用于guice?

我想" /"由普通的servlet处理。但我想" / users"由球衣处理。

假设我拥有@Path(" / users")的球衣资源。使用以下绑定将不起作用,它会尝试映射" /"要求使用球衣当然不是球衣资源,我得到404.

protected void configureServlets() {
    serve("/").with(LoginServlet.class);
    serve("/*").with(GuiceContainer.class, params);
}

我能找到的所有jersey / guice的例子都是serve("/rest/*".with(GuiceContainer.class, params); 这对我有用(" / rest / users"),但我想要一些不具备任意前缀的优秀URI,例如“休息”#39;或者' ws'。

1 个答案:

答案 0 :(得分:5)

你与“/”和“/*”。

的模糊匹配

要处理此问题,您可以使用允许使用正则表达式而非简单模式的serve方法版本。

例如,这样的事情可能有效:

serve("/").with(LoginServlet.class);
serveRegex("/.+").with(GuiceContainer.class, params);

现在,GuiceContainer映射在斜杠后至少需要一个字符。