Jersey + Guice不能将非球衣资源与球衣资源混合使用 [英] Jersey + Guice can't mix non-jersey resources with jersey resources

查看:121
本文介绍了Jersey + Guice不能将非球衣资源与球衣资源混合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将非球衣资源与球衣资源一起用于guice?

How can I use non-jersey resources with jersey resources with guice ?

我希望"/"由普通的servlet处理.但是我希望"/用户"由球衣处理.

I want "/" to be handled by a plain servlet. But I want "/users" handled by jersey.

说我有一个带有@Path("/users")的球衣资源.使用以下绑定将不起作用,它将尝试使用jersey映射"/"请求,该请求当然不是jersey资源,但我得到404.

Say I have a jersey resource with @Path("/users"). Using the following bindings will not work, it tries to map the "/" request using jersey which of course is not a jersey resource and I get 404.

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

我能找到的所有jersey/guice的示例都可以执行serve("/rest/*".with(GuiceContainer.class, params);之类的操作 哪个对我有用("/rest/users"),但是我想要一个不错的URI,它没有像'rest'或'ws'这样的任意前缀.

All of the examples of jersey / guice I can find do something like serve("/rest/*".with(GuiceContainer.class, params); which DOES work for me ("/rest/users"), but I want nice URI's that don't have some arbitrary prefix like 'rest' or 'ws'.

推荐答案

您的"/"和"/*"含义不明确.

You have an ambiguous match with "/" and "/*".

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

To handle this you can use the version of the serve method that allow a regular expression rather than a simple pattern.

例如,类似这样的方法可能会起作用:

For example, something like this may work:

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

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

The GuiceContainer mapping now requires at least one character after the slash.

这篇关于Jersey + Guice不能将非球衣资源与球衣资源混合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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