简体   繁体   中英

Is it allowed to pass-through an ejb references to a used class of an ejb?

I have an EJB3 stateless session bean that uses some other ejbs to do its work. As I do not want to have all the logic in the ejb class itself, I created some classes which solve the problems. These classes are called by the ejb. To have the referenced ejbs in these classes I created a context object that holds the injected ejb references which is passed to the classes.

My question: is this allowed to store ejb references in simple object fields or must I use some special ejb reference fields? At first glance I can't see a reason why because everything is handled in one thread an transaction.

You can pass these EJB references and store them in these auxiliar classes without any risk.

Nevertheless, EJB specification encourages you to implement all the logic of your system through EJBs. So, from EJB design philosofy, you should declare these "auxiliar" classes as EJBs also (they perform business logic in the end) and inject into them the needed EJBs references to reduce the coupling (specially if the former EJB doesn't even use the injected EJBs).

Again, if you don't do it and just pass the references manually, no technicall issue should arise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM