EJB3。 JNDI 查找的工作原理

发布于 2024-12-23 00:57:36 字数 202 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟月 2024-12-30 00:57:36

您无法保证使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文