3 Replies Latest reply on Sep 19, 2011 11:11 AM by b.eckenfels

    How to inject MessageContext for MDBs?

    b.eckenfels

      When I deploy (AS 7.0.1) a EJB-JAR containing only a MessageDriven Bean it will not be able to inject the MessageDrivenContext. Looks like the type is not known:

       

      03:03:46,989 WARN  [org.jboss.as.ee.component.ResourceInjectionAnnotationParsingProcessor] (MSC service thread 1-1) Can'

      t handle @Resource for ENC name: net.eckenfels.as7example.ejb3mdb.ejbjar.EJB3MDB/mdc on class net.eckenfels.as7example.e

      jb3mdb.ejbjar.EJB3MDB since it's missing a "lookup" (or "mappedName") value and isn't of any known type

       

      The code looks like:

       

      {code}

      package net.eckenfels.as7example.ejb3mdb.ejbjar;

       

      import javax.annotation.PostConstruct;

      import javax.annotation.PreDestroy;

      import javax.annotation.Resource;

      import javax.ejb.ActivationConfigProperty;

      import javax.ejb.MessageDriven;

      import javax.ejb.MessageDrivenContext;

      import javax.jms.JMSException;

      import javax.jms.Message;

      import javax.jms.MessageListener;

      import javax.sql.DataSource;

       

       

      @MessageDriven(name = "EJB3MDB", activationConfig = {

        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/MyQueue"),

        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})

      public class EJB3MDB implements MessageListener

      {

          private DataSource dataSource;

         

          @Resource

          MessageDrivenContext mdc;

       

          @Resource(mappedName = "java:jboss/datasources/ExampleDS")

          public void setDataSource(DataSource dataSource)

          {

              this.dataSource = dataSource;

          }

       

          @PostConstruct

          public void initialize()

          {

      ...

          }

       

          @PreDestroy

          public void cleanup()

          {

      ...

          }

       

          public void onMessage(Message message)

          {

      ...

          }

      }

      {code}