Java Bean 和企业 Java Bean 之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2460048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between Java Bean and Enterprise Java Beans?
提问by GuruKulki
Are they different or they are used interchangeably? If they are Different, then what made them different from each other?
它们是不同的还是可以互换使用?如果它们不同,那么是什么使它们彼此不同?
采纳答案by JUST MY correct OPINION
A JavaBean is just a plain old Java object that conforms to certain conventions including the use of accessor functions (getFoo/setFoo) for member access, provision of a default constructor and a few other things like that.
JavaBean 只是一个普通的旧 Java 对象,它符合某些约定,包括使用访问器函数 (getFoo/setFoo) 进行成员访问、提供默认构造函数和其他一些类似的东西。
An Enterprise JavaBean is a component in a Java EE application server which comes in several flavours, the details of which vary by which version of Java EE you're talking about (or, more specifically, which specific set of EJB specifications are involved).
Enterprise JavaBean 是 Java EE 应用程序服务器中的一个组件,它有多种风格,其详细信息因您所讨论的 Java EE 版本而异(或者更具体地说,涉及哪一组特定的 EJB 规范)。
JavaBeans were originally mostly intended to be used in builder tools by providing a known interface which could be looked for through introspection in the tools. They quickly turned into what amounts to a religion, however.
JavaBeans 最初主要用于通过提供一个已知的接口在构建器工具中使用,该接口可以通过工具中的自省来查找。然而,他们很快就变成了一种宗教。
Enterprise JavaBeans are intended to provide encapsulated business logic for enterprise applications within a general container that provided things like session management, security, resource pooling, etc. as services thus allowing the business logic to be (relatively) untainted by these cross-cutting concerns. (Whether or not they accomplished this is a matter that is up for debate, given how difficult they were to use at first. More recent versions of the specification have made this easier, however. Legacy apps, though, are still a pain and sadly likely the majority of the EJBs you're likely to encounter.)
Enterprise JavaBeans 旨在为通用容器内的企业应用程序提供封装的业务逻辑,该容器提供会话管理、安全性、资源池等作为服务的服务,从而允许业务逻辑(相对)不受这些横切关注点的污染。(考虑到他们一开始使用起来有多困难,他们是否完成了这一点是一个有争议的问题。然而,最新版本的规范使这变得更容易。不过,遗留应用程序仍然很痛苦,令人遗憾的是可能是您可能遇到的大多数 EJB。)
Edited to add:
编辑添加:
- You can read the EJB API right here: http://java.sun.com/products/ejb/javadoc-3_0-fr/
- You can read the full specification of a JavaBean right here: http://java.sun.com/javase/6/docs/api/java/beans/package-summary.html
- 您可以在此处阅读 EJB API:http: //java.sun.com/products/ejb/javadoc-3_0-fr/
- 您可以在此处阅读 JavaBean 的完整规范:http: //java.sun.com/javase/6/docs/api/java/beans/package-summary.html
回答by saugata
Java beans refers to classes with only fields and their getter-setter methods. With little or preferably no business logic at all. They are also known as POJO (Plain Old Java Object).
Java bean 指的是只有字段及其 getter-setter 方法的类。几乎没有或最好没有业务逻辑。它们也被称为 POJO(Plain Old Java Object)。
EJB's are part of J2EE specification that can be used to leverage full functionality of J2EE compliant servers, such as transactions, session management, security etc. (That does not mean that you cannot use these without using EJBs)
EJB 是 J2EE 规范的一部分,可用于利用 J2EE 兼容服务器的全部功能,例如事务、会话管理、安全性等。(这并不意味着不使用 EJB 就不能使用这些)
回答by sbose
A Java Bean is defined as an instance of a class that contains private attributes (data), and getter & setter methods.
Java Bean 被定义为包含私有属性(数据)以及 getter 和 setter 方法的类的实例。
If you have:
如果你有:
private String myString;
in your class, you should have the methods
public String getMyString ();
and public void setMyString (String settingString);
defined in your code. Although, I have found that it is not absolutely necessary to have everything defined, just don't be surprised if something breaks!
private String myString;
在你的类中,你应该有方法
public String getMyString ();
并public void setMyString (String settingString);
在你的代码中定义。虽然,我发现定义所有内容并不是绝对必要的,但如果出现问题,请不要感到惊讶!
An EJB (Enterprise Java Bean) is much more complex They only reside in application servers that handle EJBs (Tomcat doesn't hold EJBs). There are 3 types of EJBs:
EJB(企业 Java Bean)要复杂得多。它们只驻留在处理 EJB 的应用服务器中(Tomcat 不持有 EJB)。有 3 种类型的 EJB:
- Session: Usually contain some business logic.
- Entity: Usually interface with a data store (such as a database).
- Message-Driven: Receives messages from JMS.
- Session:通常包含一些业务逻辑。
- 实体:通常与数据存储(如数据库)接口。
- 消息驱动:从 JMS 接收消息。
回答by user2790341
"Java Beans" are used to store the data retrieved data from the database and used as a container to carry the data between the Servlets and JSPs in MVC model. A class (container) with setters and getters is used to (put) and (get) the data.
“Java组件”用于存储数据检索的数据从数据库中并用作容器携带在Servlet和JSP之间的数据MVC模式。带有 setter 和 getter 的类(容器)用于(放置)和(获取)数据。
"Enterprise Java Beans" are similar to "Java Beans" with added features such as Session Management, Security, Transaction etc with the aid of different types of EJBs that are
“企业Java Beans”是类似于“Java组件”增值功能,例如会话管理,安全性,事务等与不同类型的EJB的援助是
- Session Bean
- Entity Bean
- Message Driven Beans
- 会话豆
- 实体豆
- 消息驱动的 Bean