2 Replies Latest reply on May 26, 2006 10:06 AM by cybernd

    embeddable-a6 + mdb dependency injection

    cybernd

      Hi

      Just startet to write unit tests using the embeddable-alpha6 ejb3 container.

      I got StatelessSessionBeans as some kind of DAO layer.
      Now i want to access this DAO from my MDB.

      Working szenario:

      @Stateless(name = "ADao")
      public class ADao) {
       @EJB(beanName = "BDao")
       BDao bDao;
      
      }
      
      @Stateless(name = "BDao")
      public class BDao) {
      
      }


      This example works and im able to call a method from the ADao which itself will call a method of the injected BDao. Works well.

      Now i try to create a MDB which will use BDao:

      @MessageDriven(activationConfig = {
       @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
       @ActivationConfigProperty(propertyName = "destination", propertyValue = "MyTopic") })
      public class MyMDB implements MessageListener {
       private static final Logger log = Logger.getLogger(MachineStatusMDB.class);
      
       @EJB(beanName = "BDao")
       BDao bDao;
      }
      


      When i send a message to the topic JBoss throws an Exception because he is unable to inject bDao into the MDB. When i remove the Injection, the mdb onMessage gets called, so the MDB itself works proper - just the @EJB injection fails there.

      Both examples use the same injection annotation:
       @EJB(beanName = "BDao")
       BDao bDao;
      

      but there are different behaviors between the MDB usage and the SLSB usage.

      The stacktraces:
      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: local not bound]
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at org.jboss.ejb3.injection.JndiFieldInjector.inject(JndiFieldInjector.java:69)
       at org.jboss.ejb3.injection.JndiFieldInjector.inject(JndiFieldInjector.java:61)
       at org.jboss.ejb3.AbstractPool.create(AbstractPool.java:88)
       at org.jboss.ejb3.ThreadlocalPool.get(ThreadlocalPool.java:48)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:51)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.mdb.MDB.localInvoke(MDB.java:949)
       at org.jboss.ejb3.mdb.MDB$MessageListenerImpl.onMessage(MDB.java:1179)
       at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:266)
       at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:902)
       at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
       at org.jboss.mq.SpySession.run(SpySession.java:323)2006-05-26 13:55:39,187 ERROR [JMS SessionPool Worker-0](StdServerSession.java:270) session failed to run; setting rollback only
      java.lang.RuntimeException: Unable to inject jndi dependency: env/test.MyMDB/bDao into field test.BDao test.MyMDB.bDao
       at org.jboss.ejb3.injection.JndiFieldInjector.inject(JndiFieldInjector.java:74)
       at org.jboss.ejb3.injection.JndiFieldInjector.inject(JndiFieldInjector.java:61)
       at org.jboss.ejb3.AbstractPool.create(AbstractPool.java:88)
       at org.jboss.ejb3.ThreadlocalPool.get(ThreadlocalPool.java:48)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:51)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.mdb.MDB.localInvoke(MDB.java:949)
       at org.jboss.ejb3.mdb.MDB$MessageListenerImpl.onMessage(MDB.java:1179)
       at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:266)
       at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:902)
       at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
       at org.jboss.mq.SpySession.run(SpySession.java:323)
       at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:194)
       at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: local not bound]
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at org.jboss.ejb3.injection.JndiFieldInjector.inject(JndiFieldInjector.java:69)
       ... 14 more
      Caused by: javax.naming.NameNotFoundException: local not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061)
       ... 17 more
       at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:194)
       at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.naming.NameNotFoundException: local not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061)
       ... 17 more
      


      thx for your help
      Bernhard