How to do filter-mapping with servlet-name in Guice Servlet?
In my web.xml I have
<filter>
<filter-name>authFilter</filter-name>
<filter-class>com.mystuff.AuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>authFilter</filter-name>
<servlet-name>requestFactoryServlet</servlet-name>
</filter-mapping>
<!-- Servlets -->
<servlet>
<servlet-name>requestFactoryServlet</servlet-name>
<servlet-class>com.google.web.bindery.requestfactory.server.RequestFactoryServlet</servlet-class>
<init-param>
<param-name>symbolMapsDirectory</param-name>
<!-- You'll need to compile with -extras and move the symbolMaps directory
to this location if you want stack trace deobfusca开发者_如何学Pythontion to work -->
<param-value>WEB-INF/classes/symbolMaps/</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>requestFactoryServlet</servlet-name>
<url-pattern>/gwtRequest</url-pattern>
</servlet-mapping>
and I am attempting to convert this to use Guice Servlet configuration rather than the web.xml configuration.
I cannot figure out how to do the equivalent of the of the in Guice. I only see examples of how to filter patterns, not specific servlets.
Define a Guice listener in web.xml :
<listener>
<listener-class>xxx.GuiceServletConfig</listener-class>
</listener>
And implement this listener :
public class GuiceServletConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
return Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
Map<String, String> params = new HashMap<String, String>();
params.put("symbolMapsDirectory", "WEB-INF/classes/symbolMaps/");
serve("/gwtRequest").with(RequestFactoryServlet.class, params);
}
});
}
}
精彩评论