dev@glassfish.java.net

Re: Debugging Dependency Injection in GlassFish

From: Jerome Dochez <jerome.dochez_at_oracle.com>
Date: Tue, 4 Jan 2011 09:58:58 -0800

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 ?

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 ?

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