[jboss-dev-forums] [JBoss AS7 Development] - CDI bean injection problem

Andrew Murphy do-not-reply at jboss.com
Mon Jul 18 19:27:09 EDT 2011


Andrew Murphy [http://community.jboss.org/people/Smurfs] created the discussion

"CDI bean injection problem"

To view the discussion, visit: http://community.jboss.org/message/615942#615942

--------------------------------------------------------------
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
[http://community.jboss.org/message/615942#615942]

Start a new discussion in JBoss AS7 Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20110718/637140f3/attachment.html 


More information about the jboss-dev-forums mailing list