users@jersey.java.net

[Jersey] Re: jersey-guice: Missing dependency for constructor

From: Gili <gili.tzabari_at_gmail.com>
Date: Fri, 14 Jan 2011 23:33:31 -0800 (PST)

It turns out that the existence of a DefaultResourceConfig subclass was
overriding Guice's servlet filter defined in web.xml.

@ApplicationPath("/*")
public class ApplicationConfig extends DefaultResourceConfig
{
}

Once I removed this class Guice injection worked as expected. The next
question was how to combine GuiceServletContextListener and
DefaultResourceConfig. Maybe I'm particularly slow after working at this for
hours but it really wasn't obvious how to accomplish this. When I use
DefaultResourceConfig, Jersey automatically registers a whole bunch of
Mappers and Providers for me:

INFO: Instantiated the Application class
com.foo.health.server.ApplicationConfig. The following root resource and
provider classes are registered: [class
org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider, class
org.codehaus.jackson.jaxrs.JsonParseExceptionMapper, class
com.foo.health.server.DoctorsResource, class
org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper, class
org.codehaus.jackson.jaxrs.JacksonJsonProvider]

If you follow the documentation for GuiceServletContextListener you won't
end up with any of these important mappers/providers. Anyway, a few hours
later I figured it out.

Paul, can you please update
http://jersey.java.net/nonav/apidocs/latest/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
to mention the following important line of code?

params.put(ServletContainer.RESOURCE_CONFIG_CLASS,
ClasspathResourceConfig.class.getName());

Hopefully it'll save others some time in the future :)

Thank you,
Gili
-- 
View this message in context: http://jersey.576304.n2.nabble.com/jersey-guice-Missing-dependency-for-constructor-tp5920703p5924265.html
Sent from the Jersey mailing list archive at Nabble.com.