I'm trying out a jersey application with guice dependency injection. Everything works fine when I load the GuiceFilter through web.xml. But when I register the filter using guice api as given below, jersey do not get initialized.

protected void configureServlets() {
    final Map<String, String> params = new HashMap<String, String>();
    params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "com.mypackage.rest");
    bind(MyInterface.class).to(MyImpl.class);
    filter("/*").through(GuiceFilter.class);
    serve("/*").with(GuiceContainer.class, params);
}
有帮助吗?

解决方案

You do not need to register Guice filter inside Guice filter. It should be registered directly in your servlet container, in web.xml or in the code which creates your servlet container (embedded Jetty, for example). Other servlets and filters, on the other hand, can be registered in Guice filter.

If you won't register Guice filter in your servlet container, how it would know that you want to pass your requests through this filter?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top