users@jersey.java.net

IoCComponentProviderFactory and injection of Jersey-based artifacts ?

From: Morten <mortench2004_at_yahoo.dk>
Date: Wed, 22 Jul 2009 21:13:47 +0000 (GMT)

I have a question about how to inject  Jersey-based artifacts with IoC managed artifacts and how to properly support javax's @Postconstruct. I.e. how to support injection and @Postconstruct to be fully supported for a mix of Jersey and a custom Ioc manged artifacts....I have something working partly as detailed below but have been unable to get constructor injection and @Postconstruct working fully.

My situation is that I have a custom mini IvC framework that can inject non-jersey artifacts and I want to use this on jersey controllers besides the build-in jersey artifacts already supported by @Context.

So far, I have sucessfully implemented a com.sun.jersey.core.spi.component.ioc.. IoCComponentProviderFactory. This factory delegates construction of our IvC resources to our own IvC framework using IoCManagedComponentProvider. We can thus create and inject our own Ivc artifacts without problem and jersey will follow up with injecting jersey artifacts into the controller fields once they are returned by our factory

So far so good. Remaining problems are:

1) How to inject jersey artifacts into the constructor? The IoCFullyManagedComponentProvider javadoc notes that another factory "IoCComponentProcessorFactory" may be used for this purpose inside our factory, but how do we get hold of an instance of the class IoCComponentProcessorFactory ?

2) How to call @Postconstruct once Jersey has finished injecting its jersey artifacts? Currently, we do this at the end of our implementation of IoCComponentProviderFactory but this is too early as Jersey then has had no chance yet to inject it's artifacts yet (done by jersey after our factory returns the object).