Jersey + Guice + Tomcat producing 404 when served with something other than root directory

断了今生、忘了曾经 提交于 2019-12-11 23:32:28

问题


I have a resource that looks like this:

@Path("/Resources/Console")
public class ConsoleResource {

    @POST
    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public String post(/* */) {
        /* */
    }

}

Whenever my JerseyServletModule is configured as follows, the services work:

@Override
protected void configureServlets() {
    bind(ConsoleResource.class);

    bind(MessageBodyReader.class).to(JacksonJsonProvider.class);
    bind(MessageBodyWriter.class).to(JacksonJsonProvider.class);

    serve("/*").with(GuiceContainer.class);
}

But things like index.html don't. Changing "/*" to "/Resources/*" causes things like index.html to work, again, but then ConsoleResource's @POST method doesn't work (I get a 404 whenever I access /Resources/Console). I assume I want to get the latter working (like this). Thoughts?

Thanks!


回答1:


The issue ended up being the server running static content through the various filters and whatnot. By editing the web.xml file to be the following:

<filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/Resources/*</url-pattern>
</filter-mapping>

And abiding by the convention that my resources would have /Resources/ as a prefix to their path, static content gets through the Guice filter.



来源:https://stackoverflow.com/questions/14634834/jersey-guice-tomcat-producing-404-when-served-with-something-other-than-root

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