JBoss Community

CDI bean injection problem

created by Andrew Murphy in JBoss AS7 Development - View the full discussion

Apologies if this query should be put to the user forum, but I'm not sure if what I face is a bug, or me just being dumb!

 

I have a bean, DownloadJob, which implements the quartz (timer) Job interface method execute(...). The bean has the @ManagedBean annotation. The problem I face is I have a number of CDI dependant beans declared within the DownloadJob bean which are not being injected i.e. all references to CDI beans remain 'null'. I suspect the underlying cause is the container is unaware of the DownloadJob bean (despite being annotated with @ManagedBean) as the quartz library instantiates it when a timer is triggered. Nonetheless my expectation is the container should still resolve calls/references to the other CDI managed beans under its control. Am I mistaken or naive?

 

Rather than paste a zillion of lines of code I have created the simple test case (zip attached) which replicates this issue by instantiating a bean with CDI dependencies using the new keyword. An excerpt of the test case is below.

 

I have the latest JBoss AS7.1 snapshot which I understand addresses a recent CDI injection bug, so any insight/guidance will be appreciated.

 

Thank you, Andrew

 

 

 

 

@RunWith(Arquillian.class)

public class SimpleCDITest {

 

    //...

 

    @Inject

    private InjectableEJB1 injectableEJB1;

 

    @Test

    public void injectedManagedBeanDependencyTest() {

         Assert.assertNotNull(injectableEJB1.getSimpleBean());

         Assert.assertNotNull(injectableEJB1.getSimpleEJB());

    }

 

    @Test

    public void instantiatedBeanDependencyTest() {

         final InjectableEJB2 injectableEJB2 = new InjectableEJB2();

        // Injected dependencies into InjectableEJB2 are null...

        // ... assert fails

        Assert.assertNotNull(injectableEJB2.getSimpleBean());

        Assert.assertNotNull(injectableEJB2.getSimpleEJB());

    }

}

Reply to this message by going to Community

Start a new discussion in JBoss AS7 Development at Community