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

前端 未结 4 808
鱼传尺愫
鱼传尺愫 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:46

    I think the problem of the very first example is that you are trying to inject the implementation of the EJB and not its interface. The local no-interface view of EJB 3.1 is just possible if you do not define any interface, not even a remote one. So changing the injection point to the following should work out:

     @EJB
     private TestBeanRemote testBean;
    

    If you are using your application within a non clustered environment, so single JVM, you should think about changing the interface to @Local. As soon as you are accessing EJBs using their remote interface, you are getting a lot of overhead. Parameters and return values can not be accessed by reference anymore, but by value, as they are always copied (specification says so). This might lead to performence issues when dealing with more complex objects.

    Hoped that helped.

提交回复
热议问题