3 Replies Latest reply on Jun 1, 2006 4:54 PM by bill.burke

    Problem with @EJB injection in a @MessageDriven bean

    sateh

      I'm having problems using standard dependency injection in a @MessageDriven bean.

      This is the code:

      @MessageDriven(........)
      public class FooQueueListener implements MessageListener
      {
       @PersistenceContext
       private EntityManager mEntityManager;
      
       @EJB(mappedName = "foo/ejb/FooBean")
       private Foo mFoo;
      
       public void onMessage(Message message)
       {
       // Problem: mFoo is always null
       }
      }
      


      When onMessage() is executed, mFoo is always null. I can see with twiddle that foo/ejb/FooBean really exists in the Global JNDI namespace though, and looking it up manually works fine:

       public void onMessage(Message message)
       {
       InitialContext initialContext = new InitialContext();
       mFoo = (Foo) initialContext.lookup("foo/ejb/FooBean");
       mFoo.blah();
       }
      


      It doesn't work in the following cases.

      Simple DI without any naming changes:

      @Local
      public interface Foo {
       void blah();
      }
      @Stateful
      public class FooBean implements Foo {
       void Blah() {}
      }
      @MessageDriven(........)
      public class FooQueueListener implements MessageListener
      {
       @EJB
       private Foo mFoo;
      }
      


      Or with a LocalBinding:

      @Local
      public interface Foo {
       void blah();
      }
      @Stateful @LocalBinding(jndiName="foo/ejb/FooBean")
      public class FooBean implements Foo {
       void Blah() {}
      }
      @MessageDriven(........)
      public class FooQueueListener implements MessageListener
      {
       @EJB(mappedName = "foo/ejb/FooBean")
       private Foo mFoo;
      }
      


      Known bug? Or am I missing something here?

      S.