users@jersey.java.net

[Jersey] Re: Dependency Injection

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Mon, 17 Dec 2012 12:52:50 +0100

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

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)
> ..
> 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
>
>
>
>