dev@glassfish.java.net

Re: Debugging Dependency Injection in GlassFish

From: Ken <ken.cavanaugh_at_oracle.com>
Date: Tue, 04 Jan 2011 10:25:15 -0800

On 01/ 4/11 09:58 AM, Jerome Dochez wrote:
> On Jan 4, 2011, at 9:36 AM, Ken wrote:
>
>
>> I've made a few changes in the FOLB code in glassfish-naming, and now some
>> of the surefire tests for naming are failing. The scenario is that SerialInitContextFactory
>> needs to call GlassFishORBHelper.getORB(). GlassFishORBHelper is annotated
>> with @Service and implements PostConstruct and ORBLocator.
>> The PostConstruct method calls
>>
>> orbFactory = habitat.getByContract( GlassFishORBFactory.class ) ;
>>
>> where habitat was obtained from @Inject on a field.
>> The tests are failing because orbFactory is null.
>>
>> ORBFactory is an @Contract interface, which is implemented
>> by GlassFishORBFactoryImpl, which is a class annotated with @Service.
>> GlassFishORBFactoryImpl also implements PostConstruct.
>>
>> So how do I debug this and figure out why getByContract returned null?
>> I haven't changed any of the annotations, so presumably something else is failing,
>> but what?
>>
>> A quick look into getByContract seems to indicate that the byContract MultiList
>> does not contain GlassFishORBFactory, but why?
>>
> does it contain anything ?
>
Yes, byContract had I think 52 entries in it (just not the one I needed).
> the first thing I would check is the content in the META-INF/inhabitants/default file in your implementation module.
> does the file exist ?
> does it have an entry for your GlassFishORBFactoryImpl service ?
>
It contains 3 entries, one of which is:

class=org.glassfish.enterprise.iiop.impl.GlassFishORBFactoryImpl,index=org.glassfish.enterprise.iiop.api.GlassFishORBFactory

which I presume is what is needed there.

Is there some runtime debugging I can do here?

Thanks,

Ken.
>
>> Another possible clue is that a breakpoint in the GlassFIshORBFactoryImpl.postConstruct method is never
>> executed. So it seems that the GlassFishORBFactoryImpl class is perhaps ignored
>> by hk2, even though it has the @Service annotation. GlassFishORBFactoryImpl has no
>> static initializer, and a default constructor, so I can't see why there should be a problem
>> instantiating this class.
>>
>> Thanks,
>>
>> Ken.
>>
>