users@jersey.java.net

[Jersey] Re: Dependency Injection

From: Tomek Sniadach <tomek.sniadach_at_gmail.com>
Date: Mon, 17 Dec 2012 14:22:36 +0100

Thanks Pavel,
this makes it a little bit clearer to me.
In the test is the provider intatiated directly. I'm using tomcat. Where is
here the place to configure the provider?

Thanks and regards
Tomek



2012/12/17 Pavel Bucek <pavel.bucek_at_oracle.com>

> Hi Tomek,
>
> have you looked at AnnotationInjectableTest in Jersey workspace? It
> basically does exactly what you want, see http://java.net/projects/**
> jersey/sources/svn/content/**trunk/jersey/jersey-tests/src/**
> test/java/com/sun/jersey/impl/**inject/**AnnotationInjectableTest.java?**
> rev=5822<http://java.net/projects/jersey/sources/svn/content/trunk/jersey/jersey-tests/src/test/java/com/sun/jersey/impl/inject/AnnotationInjectableTest.java?rev=5822>
>
> Regards,
> Pavel
>
>
> On 12/17/12 10:58 AM, Tomek Sniadach wrote:
>
>> Hi,
>> I have trouble to understand, how dependency injection in jersey works.
>> Let say, i have a class "Info" that should be instantiated at the boot time
>> (tomcat). Then i need the reference to the class in my Resource.
>> What I've done:
>> I have a class
>> public class Info implements InjectableProvider<Resource, Type> (see
>> http://jersey.576304.n2.**nabble.com/Simplest-**
>> Dependency-Injection-with-**Jersey-td3393338.html<http://jersey.576304.n2.nabble.com/Simplest-Dependency-Injection-with-Jersey-td3393338.html>
>> )
>> ..
>> This is registered as provider (I can see the log message at boot time).
>> Then I've got an error:
>> java.lang.**IllegalArgumentException: Can not set ...Info field
>> ...MyResource.a to org.apache.naming.**NamingContext
>> In MyResource I have just a Field: Info a; annotated with @Resource
>>
>> Can someone explain the mechanism in jersey or post a link, where i can
>> find more information?
>>
>> regards
>>
>> Tomek
>>
>>
>>
>>
>>
>