问题
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