EJB3. JNDI查找如何工作 [英] EJB3. How JNDI lookup works

查看:104
本文介绍了EJB3. JNDI查找如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建使用EJB 3进行数据处理的小框架.
我有从数据源抽象的实体访问对象层.现在,我需要某种工厂,它将为我提供查询实体的合适的bean.

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.

通过JNDI本地bean接口将查询作为参数传递给另一个本地bean是否安全?是像@EJB场合那样,将从此本地接口调用的每个方法都寻址到相同的bean,还是将每个调用传递给不同的无状态bean?

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?

推荐答案

您无法保证使用JNDI会给您相同的EJB实例,因此与使用@EJB@Inject. @EJB和JNDI查找之间的唯一区别是SFSB.在这种情况下,每次使用JNDI查找时,都需要该容器为您提供新的SFSB实例.

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.

但是,在我看来,在EJB 3.x和依赖项注入时代,更容易理解@EJB/@Inject批注.无需传递任何对象引用,只需使用@EJB在每个EJB中定义您的依赖项(EJB协作者).

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.

这篇关于EJB3. JNDI查找如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆