是否有任何理由在CDI会话中使用状态EJB
我正在尝试雅加达EE和雅加达面孔(JSF)。 我刚刚制作了一个名为Session scoped bean的CDI(因为JSF ManagedBean现在已弃用), 并且想知道为什么一个人会使用状态EJB 当示波豆(在CDI容器中运行)可用时,在我看来,使用注入CDI托管bean中的无状态bean可以完成任何交易。
任何现实世界中的用例都会很有帮助:)。
对于那些想知道的人,我的托管/命名bean看起来像这样:
import jakarta.ejb.EJB;
import jakarta.enterprise.context.SessionScoped;
import jakarta.inject.Named;
@Named("userBean")
@SessionScoped
public class UserSessionBean implements java.io.Serializable{
@EJB
TransactionBean bean; //can be used to persist user data
String username;
String password;
// Constructor, getters and setters
}
I am experimenting with Jakarta EE and Jakarta Faces (JSF).
I just made a CDI named session scoped bean (as JSF managedBean's are deprecated now),
and was wondering why one would use a stateful EJB when scoped beans (running in the CDI container) are available, it seems to me that any transactions can be done using a stateless bean injected into the CDI managed bean.
Any real-world use cases would be really helpful :).
For those wondering, my Managed/named bean looks like this:
import jakarta.ejb.EJB;
import jakarta.enterprise.context.SessionScoped;
import jakarta.inject.Named;
@Named("userBean")
@SessionScoped
public class UserSessionBean implements java.io.Serializable{
@EJB
TransactionBean bean; //can be used to persist user data
String username;
String password;
// Constructor, getters and setters
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
容器)实际上几乎从来没有 。无论如何,国家企业豆从来都不是(范围)支持Bean,即使仍然建议使用EJB,状态变化也很少使用Web应用程序。
最初,使用CORBA/RMI(例如,作为一种二进制servlet),将其用作远程组件时,状态企业Bean最初具有更大的实用性。
现在,当利用雅加达持久性(JPA)的扩展持久性环境时,现在有一个高度专业化,有些晦涩的用例。在过去的十年中,我们从未设法为其他豆类除了州的bean以外的其他豆类指定其行为。
Practically speaking almost never. Stateful Enterprise Beans were never intended as (scoped) backing beans anyway, and even when EJB was still recommended to be used, the stateful variation had little usage in web applications.
Originally the stateful enterprise bean had more utility when using it as a remote component using CORBA/RMI (e.g., as a kind of binary Servlet).
There's a highly specialised and somewhat obscure use-case for them now when taking advantage of the extended persistence context in Jakarta Persistence (JPA). Somehow in over a decade we never managed to specify its behaviour for other beans than stateful session beans.