Java EE 到底是什么?
我从事 Java SE 工作已经有几年了,现在正在转向 Java EE。但是,我在理解 Java EE 的某些方面遇到了一些困难。
-
Java EE 只是一个规范吗?我的意思是:EJB 是 Java EE 吗?
-
EJB/Spring 是 Java EE 的不同实现吗?
很抱歉,我很难理解 Java EE 是什么。
有人能解释一下什么是Java EE吗?还有 EJB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
(2023 年 5 月更新)
首先,自 2019 年 9 月起,“Java EE”已更名为“Jakarta EE”,从版本 8 开始历史上,还有一个术语“J2EE”,涵盖版本 1.2 到 1.4。术语“Java EE”涵盖版本 5 到 8。另请参阅Jakarta EE,维基百科上的历史。
Jakarta EE 确实是一个抽象规格。任何人都愿意开发并提供该规范的有效实现。具体的实现是所谓的应用程序服务器,例如 WildFly、TomEE, GlassFish, 自由,WebLogic 等。还有一些 servlet 容器,仅实现庞大的 Jakarta EE API 的 JSP/Servlet 部分,例如 Tomcat、Jetty 等。
我们,Jakarta EE 开发人员,应该利用规范编写代码(即在我们的代码中导入 仅
jakarta.*
类,而不是实现特定的类,例如org.jboss.wildfly.*,
com.sun.glassfish.*
、org.apache.tomcat.*
等),然后我们就可以在任何实现上运行我们的代码(因此,任何应用程序服务器)。如果您熟悉 JDBC,它与 JDBC 驱动程序的工作原理基本上是相同的概念。另请参阅用最简单的术语来说,什么是工厂?EJB 是Jakarta EE 规范的一部分。看,它位于 Jakarta EE API 中。成熟的 Jakarta EE 应用服务器开箱即用地支持它,但简单的 JSP/Servlet 容器则不支持。
另请参阅:
不,正如前面所说,EJB 是 Jakarta EE 的一部分。 Spring 是一个独立的框架,它替代并改进了 Jakarta EE 的许多部分。 Spring 不一定需要 Jakarta EE 才能运行。像 Tomcat 这样的基本 servlet 容器就已经足够了。简单地说,Spring 是 Jakarta EE 的竞争对手。例如,“Spring”(独立)与 EJB/JTA 竞争,Spring MVC 与 Faces/REST/MVC 竞争,Spring DI/IoC/AOP 与 CDI 竞争,Spring Security 与 JASPIC/Security 竞争,Spring Boot 与 MicroProfile 竞争,等等。
回到旧的 J2EE/ EJB2 时代,EJB2 API 的实现和维护非常糟糕。 Spring 是 EJB2 更好的替代品。但自 EJB3 (Java EE 5) 以来,EJB API 基于 Spring 的经验教训得到了很大改进。自 CDI (Java EE 6) 以来,没有真正的理由再次考虑另一个像 Spring 这样的框架来让开发人员更容易地开发服务层等。
仅当您使用 Tomcat 等简单的 servlet 容器并且无法转移到 Jakarta EE 服务器时,Spring 才更具吸引力,因为在 Tomcat 上安装 Spring 更容易。如果不修改服务器本身,就不可能在 Tomcat 上安装 EJB 容器,这基本上是在重新发明 TomEE。
另请参阅:
(Updated May 2023)
First of all, "Java EE" has since Sep 2019 been renamed to "Jakarta EE", starting with version 8. Historically, there was also the term "J2EE" which covered versions 1.2 until 1.4. The term "Java EE" covered versions 5 until 8. See also Jakarta EE, History on Wikipedia.
Jakarta EE is indeed an abstract specification. Anybody is open to develop and provide a working implementation of the specification. The concrete implementations are the so-called application servers, like WildFly, TomEE, GlassFish, Liberty, WebLogic, etc. There are also servlet containers which implement only the JSP/Servlet part of the huge Jakarta EE API, such as Tomcat, Jetty, etc.
We, Jakarta EE developers, should write code utilizing the specification (i.e. import only
jakarta.*
classes in our code instead of implementation specific classes such asorg.jboss.wildfly.*
,com.sun.glassfish.*
,org.apache.tomcat.*
, etc) and then we'll be able to run our code on any implementation (thus, on any application server). If you're familiar with JDBC, it's basically the same concept as how JDBC drivers work. See also a.o. In simplest terms, what is a factory?EJB is part of the Jakarta EE specification. Look, it's in the Jakarta EE API. Full-fledged Jakarta EE application servers support it out the box, but simple JSP/Servlet containers don't.
See also:
No, as said, EJB is part of Jakarta EE. Spring is a standalone framework which substitutes and improves many parts of Jakarta EE. Spring doesn't necessarily require Jakarta EE to run. A bare-bones servlet container like Tomcat is already sufficient. Simply put, Spring is a competitor of Jakarta EE. E.g. "Spring" (standalone) competes EJB/JTA, Spring MVC competes Faces/REST/MVC, Spring DI/IoC/AOP competes CDI, Spring Security competes JASPIC/Security, Spring Boot competes MicroProfile, etc.
Back during the old J2EE/EJB2 times, the EJB2 API was terrible to implement and maintain. Spring was then a much better alternative to EJB2. But since EJB3 (Java EE 5), the EJB API was much improved based on lessons learnt from Spring. Since CDI (Java EE 6), there's not really a reason to look at again another framework like Spring to make the developers more easy as to developing among others the service layer.
Only when you're using a bare-bones servlet container such as Tomcat and can't move on to a Jakarta EE server, then Spring is more attractive as it's easier to install Spring on Tomcat. It isn't possible to install e.g. an EJB container on Tomcat without modifying the server itself, you would basically be reinventing TomEE.
See also:
Java Enterprise Edition (Java EE) 是一个总括规范,引用了许多其他更详细的规范,其中 Enterprise JavaBeans (EJB) 是最重要的规范之一。
阅读此 - 它解释了 Java EE 和 Spring 之间的区别,
谢谢。 ..
Java Enterprise Edition (Java EE) is an umbrella specification that references a number of other more detailed specifications, of which Enterprise JavaBeans (EJB) is one of the more important ones.
Read this - it explains the difference between Java EE and Spring
Thanks...
来源 -- Java 2 Platform, Enterprise Edition (J2EE) 定义了开发组件的标准 -基于多层企业应用程序。 J2EE 简化了企业应用程序的构建,这些应用程序是可移植的、可扩展的,并且可以轻松地与遗留应用程序和数据集成。
来源 -- Enterprise JavaBeans (EJB) 技术是Java Platform, Enterprise Edition (Java EE) 的服务器端组件架构。 EJB 技术支持快速、简化地开发基于 Java 技术的分布式、事务性、安全和可移植应用程序。
Java EE 只是一个规范吗?我的意思是:EJB 是 Java EE 吗?
Java EE 是一个规范。
EJB 是 Java EE 的服务器端组件架构
Source -- Java 2 Platform, Enterprise Edition (J2EE) defines the standard for developing component-based multitier enterprise applications. J2EE simplifies building enterprise applications that are portable, scalable, and that integrate easily with legacy applications and data .
Source -- Enterprise JavaBeans (EJB) technology is the server-side component architecture for Java Platform, Enterprise Edition (Java EE). EJB technology enables rapid and simplified development of distributed, transactional, secure and portable applications based on Java technology.
Java EE is a specification.
EJB is server side component architecture for Java EE
您需要了解的有关 Java EE 的所有信息都可以通过@ Oracle 官方网站找到网站等。您可能还会对阅读版本 8 的规范 API 感兴趣。值得花时间阅读 Java EE 8 教程。您可能实际上想从它开始,因为它提供了整个平台的非常好的概述。
Everything you need to know about Java EE may be found by starting @ Oracle official website, among other. You may also find interesting to read the specification APIs for release 8. It is worth taking the time to go through the Java EE 8 tutorial. You may want to start with it actually, because it provides a very good overview of the whole platform.
Java EE 作为规范:
Java EE 确实是一个规范,定义了一组用于开发企业应用程序的 API 和技术。它提供了构建可扩展、安全且强大的应用程序的标准。 Java EE 指定了不同组件在企业应用程序环境中应如何交互。
Java EE 中的 EJB(企业 JavaBean):
EJB 是 Java EE 中的一个组件模型,它定义了一组用于构建分布式、事务性和安全的企业应用程序的服务器端组件。 EJB 提供事务管理、安全性和可伸缩性等功能。 EJB 是 Java EE 规范的一部分,专门针对业务逻辑组件。
Spring 框架:
Spring 不是 Java EE 规范的一部分。它是一个开源框架,为构建企业应用程序提供了全面的编程和配置模型。 Spring 提供了依赖注入、面向方面编程以及对各种技术的支持等功能。虽然 Spring 可用于构建企业应用程序,但它不是 Java EE 的实现。
Java EE 的不同实现:
不同的供应商提供了 Java EE 规范的实现。这些实现包括 Apache TomEE、WildFly、IBM WebSphere 和 Oracle WebLogic 等应用程序服务器。这些应用程序服务器提供运行时环境和基础设施来部署和运行符合规范的 Java EE 应用程序。
Java EE as a Specification:
Java EE is indeed a specification that defines a set of APIs and technologies for developing enterprise applications. It provides a standard for building scalable, secure, and robust applications. Java EE specifies how different components should interact within an enterprise application environment.
EJB (Enterprise JavaBeans) in Java EE:
EJB is a component model within Java EE that defines a set of server-side components for building distributed, transactional, and secure enterprise applications. EJBs provide features like transaction management, security, and scalability. EJB is a part of the Java EE specification, specifically targeting business logic components.
Spring Framework:
Spring is not a part of the Java EE specification. It is an open-source framework that provides a comprehensive programming and configuration model for building enterprise applications. Spring offers features like dependency injection, aspect-oriented programming, and support for various technologies. While Spring can be used to build enterprise applications, it is not an implementation of Java EE.
Different Implementations of Java EE:
Various vendors provide implementations of the Java EE specification. These implementations include application servers like Apache TomEE, WildFly, IBM WebSphere, and Oracle WebLogic. These application servers provide the runtime environment and infrastructure to deploy and run Java EE applications that comply with the specification.
J2EE/JEE/Jakarta EE
网络服务。
不同机器/层
J2EE/JEE/Jakarta EE
web services.
different machines/tiers
简单地说——JavaEE是一个平台。
它由许多规范组成,而这些规范只是 API。这些API的具体具体实现就是所谓的“参考实现”
EJB是Enterprise Java Beans
To put simply - JavaEE is a platform.
It is made up of many specifications which are just APIs. The specific concrete implementations of these APIs are the so called 'Reference Implementation'
EJB is Enterprise Java Beans