【问题标题】:Jersey + Guice can't mix non-jersey resources with jersey resourcesJersey + Guice 不能将非球衣资源与球衣资源混合使用
【发布时间】:2012-03-04 16:11:03
【问题描述】:

如何通过 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”),但我想要没有像“rest”或“ws”这样的任意前缀的漂亮 URI。

【问题讨论】:

    标签: java jersey guice


    【解决方案1】:

    您与“/”和“/*”的匹配不明确。

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

    例如,这样的事情可能会起作用:

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

    GuiceContainer 映射现在要求斜线后至少有一个字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多