EJB3. How JNDI lookup works

元气小坏坏 提交于 2019-12-11 16:51:58

问题


I'm building little framework for data processing with EJB 3.
I have Entity Access Object tier which abstracts from data source. Now I need some kind of factory which will give me right bean to query entities.

Is it safe to pass looked up through JNDI local bean interfaces as parameters to another local beans? Will each method invocation from this local interface be addressed to the same bean or each call will be passed to different stateless beans as in @EJB occasion?


回答1:


You don't have any guarantee that using JNDI you will give you the same EJB instance, so it's the same as with dependency injection using @EJB or @Inject. The only difference between @EJB and JNDI lookup is the SFSB. In this case, the container is required to provide you new SFSB instance every time you use JNDI lookup.

However, in my opinion, in EJB 3.x and dependency injection era, it's more easy to understand the @EJB/@Inject annotation. No need to pass any object references, just define your dependencies (EJB collaborators) in each EJB using @EJB.



来源:https://stackoverflow.com/questions/8616285/ejb3-how-jndi-lookup-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!