EJB3。 JNDI 查找的工作原理
我正在使用 EJB 3 构建数据处理的小框架。
我有从数据源抽象的实体访问对象层。现在我需要某种工厂来为我提供正确的 bean 来查询实体。
将通过 JNDI 本地 bean 接口查找的内容作为参数传递给另一个本地 bean 是否安全?来自该本地接口的每个方法调用是否都会被寻址到同一个 bean,或者每个调用将被传递到不同的无状态 bean(如 @EJB 场合)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法保证使用 JNDI 将为您提供相同的 EJB 实例,因此它与使用
@EJB
或@Inject
进行依赖项注入相同。@EJB
和 JNDI 查找之间的唯一区别是 SFSB。在这种情况下,每次使用 JNDI 查找时,容器都需要为您提供新的 SFSB 实例。不过,在我看来,在 EJB 3.x 和依赖注入时代,
@EJB
/@Inject
注解更容易理解。无需传递任何对象引用,只需使用@EJB
在每个 EJB 中定义您的依赖项(EJB 协作者)。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
.