How to inject a Session Bean into a Message Driven Bean?

前端 未结 4 926
鱼传尺愫
鱼传尺愫 2021-01-19 00:43

I\'m reasonably new to Java EE, so this might be stupid.. bear with me pls :D

I would like to inject a stateless session bean into a message-driven bean. Basically,

4条回答
  •  日久生厌
    2021-01-19 01:50

    Could you try to define things like this:

    @Remote
    public interface TestBeanRemote {
    
      public void doSomething();
    }
    
    @Stateless(name="TestBeanRemote")
    public class TestBean implements TestBeanRemote {
    
      public void doSomething() {
        // business logic goes here
      }
    }
    

    And then in the MDB:

    @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(beanName="TestBeanRemote")
        private TestBeanRemote testBean;
    
        public TestController() {
        }
    
        public void onMessage(Message message) {
          testBean.doSomething();
        }
    }
    

    If this work, I'll try to provide an explanation :)

提交回复
热议问题