Question

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);
}
Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top