title: How to inject a Session Bean into a Message Driven Bean?
body: <p>I'm reasonably new to Java EE, so this might be stupid.. bear with me pls :D</p>
  
  <p>I would like to inject a stateless session bean into a message-driven bean. Basically, the MDB gets a JMS message, then uses a session bean to perform the work. The session bean holds the business logic.</p>
  
  <p>Here's my Session Bean:</p>
  
  <pre><code>@Stateless
  public class TestBean implements TestBeanRemote {
  
    public void doSomething() {
      // business logic goes here
    }
  }
  </code></pre>
  
  <p>The matching interface:</p>
  
  <pre><code>@Remote
  public interface TestBeanRemote {
  
    public void doSomething();
  }
  </code></pre>
  
  <p>Here's my MDB:</p>
  
  <pre><code>@MessageDriven(mappedName = "jms/mvs.TestController", activationConfig =  {
  @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
  @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
      })
  public class TestController implements MessageListener {
  
   @EJB
   private TestBean testBean;
  
      public TestController() {
      }
  
      public void onMessage(Message message) {
        testBean.doSomething();
      }
  }
  </code></pre>
  
  <p>So far, not rocket science, right?</p>
  
  <p>Unfortunately, when deploying this to glassfish v3, and sending a message to the appropriate JMS Queue, I get errors that glassfish is unable to locate the TestBean EJB:</p>
  
  <pre><code>java.lang.IllegalStateException: Exception attempting to inject Remote ejb-ref name=mvs.test.TestController/testBean,Remote 3.x interface =mvs.test.TestBean,ejb-link=null,lookup=null,mappedName=,jndi-name=mvs.test.TestBean,refType=Session into class mvs.test.TestController
  Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=mvs.test.TestController/testBean,Remote 3.x interface =mvs.test.TestBean,ejb-link=null,lookup=null,mappedName=,jndi-name=mvs.test.TestBean,refType=Session into class mvs.test.TestController
  Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/mvs.test.TestController/testBean' in SerialContext  [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=mvs.test.TestController/testBean,Remote 3.x interface =mvs.test.TestBean,ejb-link=null,lookup=null,mappedName=,jndi-name=mvs.test.TestBean,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'mvs.test.TestBean#mvs.test.TestBean' [Root exception is javax.naming.NamingException: Lookup failed for 'mvs.test.TestBean#mvs.test.TestBean' in SerialContext  [Root exception is javax.naming.NameNotFoundException: mvs.test.TestBean#mvs.test.TestBean not found]]]
  </code></pre>
  
  <p>So my questions are:</p>
  
  <ul>
  <li>is this the correct way of injecting a session bean into another bean (particularly a message driven bean)?</li>
  <li>why is the naming lookup failing?</li>
  </ul>