Jersey + Guice can't mix non-jersey resources with jersey resources

微笑、不失礼 提交于 2019-12-07 17:22:17

问题


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

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

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

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'.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/9556495/jersey-guice-cant-mix-non-jersey-resources-with-jersey-resources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!