jsf bean 和 ejb bean 之间的区别

发布于 2024-10-04 18:00:51 字数 287 浏览 0 评论 0原文

我需要一些澄清。我知道如何使用 JSF 及其相应的会话 bean,但我对 EJB 感到困惑。 EJB 引入的 bean 和 JSF 使用的会话 bean 之间有什么区别(对于 ejb,我了解无状态/完整会话 bean 和实体 bean、实体管理器等)。我只是不明白什么时候使用 EJB 以及什么时候使用 jsf beans。除了实体 bean 之外,ejb 有状态/无状态会话 bean 看起来都与 jsf 会话 bean 相似。我读过有关将 ejb 注入 jsf 的内容,但为什么不将 ejb 与 jsf beans 结合使用呢?希望你能理解我的困惑。谢谢。

I need some clarification. I know how to work with JSF and its corresponding session beans, but i am getting confused with EJB. What is the difference between the beans introduced with EJB and the session beans used with JSF (for ejb i know about the stateless/full session beans and entity beans, entity manager, etc.). What i just dont get is when to use EJB and when to use jsf beans. Aside from the entity beans, both the ejb stateful/less session beans seem similar to the jsf session beans. I've read about injection ejb's into jsf, but why not just use ejb in conjunction with jsf beans? I hope you can understand my confusion. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

睡美人的小仙女 2024-10-11 18:00:51

首先,我们需要了解JSFEJB bean之间的区别。

  1. JSF beansPOJO类,用于读取JSF的组件值。 JSF 中有两种类型的 Bean:

    • 托管 bean 是关于如何创建和初始化 java bean 的。如您所知,JSF 使用延迟初始化模型。这意味着特定作用域中的bean不是在作用域启动时创建并初始化的,而是按需创建和初始化的,即第一次需要bean时.

    • 辅助 bean 是关于特定托管 bean 所扮演的角色。这是位于页面上的组件的服务器端表示的角色。通常,支持 bean 具有请求范围,但这不是限制。

  2. EJB Bean 是一个服务器端组件,它封装了应用程序的业务逻辑。业务逻辑是实现应用程序目的的代码。

会话bean主要分为三种类型:

1.有状态会话bean

2.无状态会话bean

3.单例会话bean(ejb 3.1)

First of all, we need to know about the difference between JSF and EJB beans.

  1. JSF beans are POJO classes which used to read the component value of JSF. There are two type of beans in JSF:

    • Managed bean is about how a java bean is created and initialized. As you know, JSF uses the Lazy initialization model. It means that the bean in the particular scope is created and initialized not at the moment when the scope is started, but on-demand, i.e. when the bean is first time required.

    • Backing bean is about the role a particular managed bean plays. This is a role to be a server-side representation of the components located on the page. Usually, the backing beans have a request scope, but it is not a restriction.

  2. EJB Bean is a server-side component that encapsulates the business logic of an application. The business logic is the code that fulfills the purpose of the application.

Mainly, there are three types of session beans:

1.Statefull session bean

2.Stateless session bean

3.Singleton session bean(ejb 3.1)

内心旳酸楚 2024-10-11 18:00:51

Java EE 中不同类型的托管 bean 之间确实存在一些混淆。更让人困惑的是,Java EE 6 引入了第三种托管 bean:CDI bean。

在这个答案中,我尝试解释一下差异和相似之处: CDI 和 EJB 相比如何? 简单地说

,JSF 托管 bean 主要不提供对事务的支持,而事务是您在处理业务逻辑(尤其是 JPA)时经常需要的。

另请注意,会话范围托管 Bean 中的术语“会话”与无状态和有状态会话 Bean 中的术语所指的会话完全不同。

There is indeed some confusion between the different types of managed beans in Java EE. To add to the confusion, Java EE 6 has introduced a third kind of managed bean: a CDI bean.

In this answer I try to explain the differences and similarities a little: How do CDI and EJB compare? interact?

Briefly said, JSF managed beans mainly don't offer support for transactions, which is something you often need when working with business logic and especially JPA.

Also note that the term session as in session scoped managed beans is a completely different kind of session than the one the term in stateless and statefull session beans refers to.

墟烟 2024-10-11 18:00:51

该网站上还有另一个很好的答案,其中解释了 CDI 和 EJB 的差异。当你最终掌握整个情况时,这会很有帮助。 在哪里使用 EJB 3.1 和 CDI?

There is another gread answer on the site where the differences of CDI and EJB are explained. It helps a great deal when you finally grasp the whole picture. Where to use EJB 3.1 and CDI?

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