Hi,
I think Jersey is instantiating DoctorsResource instead of Guice.
That would imply one of two things:
1) The web.xml is incorrect; or
2) There is a bug or inconsistency in the Guice integration related
to scopes.
I suspect it might be the latter. I notice you have not declared the
scope of the DoctorsResource. Try annotating that class with the Guice
annotation @RequestScoped or @Singleton. If that is the case can you
please log an issue related to no-scope bindings.
Paul.
On Jan 14, 2011, at 6:27 AM, Gili wrote:
>
>
> Gili wrote:
>>
>> Hi,
>>
>> I created a test program according to
>> http://jersey.java.net/nonav/apidocs/latest/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
>> but for some reason whenever I try constructor injection I get:
>>
>> SEVERE: Missing dependency for constructor public
>> foo.DoctorsResource(com.holdmyspot.search.server.Test) at parameter
>> index
>> 0
>>
>> Here is my config file (I verified this is being executed at load-
>> time):
>>
>> public class GuiceConfig extends GuiceServletContextListener
>> {
>> @Override
>> protected Injector getInjector()
>> {
>> return Guice.createInjector(new JerseyServletModule()
>> {
>> @Override
>> protected void configureServlets()
>> {
>> bind(DoctorsResource.class);
>> bind(Test.class).toInstance(new Test());
>> serve("/*").with(GuiceContainer.class);
>> }
>> });
>> }
>> }
>>
>> And here is my resource:
>>
>> @Path("/doctors")
>> public class DoctorsResource
>> {
>> private final Test test;
>>
>> @Inject
>> public DoctorsResource(Test test)
>> {
>> this.test = test;
>> }
>> }
>>
>> I am fairly certain that Guice knows how to inject Test. Why then
>> am I
>> getting this error?
>>
>> Thanks,
>> Gili
>>
>
> Adding @InjectParam to the constructor argument fixed the problem.
> That is:
>
> @Inject
> public DoctorsResource(@InjectParam Test test)
> {
> this.test = test;
> }
>
> Why does this work? And why isn't this mentioned by the aforementioned
> Javadoc? :)
>
> Thanks,
> Gili
> --
> View this message in context: http://jersey.576304.n2.nabble.com/jersey-guice-Missing-dependency-for-constructor-tp5920703p5920726.html
> Sent from the Jersey mailing list archive at Nabble.com.