简体   繁体   English

会话Bean和EJB3与Spring

[英]Session Beans and EJB3 vs Spring

I was curious about the capabilities of Sessions Beans in EJB 3 and whether they can be replaced in a typical mid-scale enterprise application with Spring. 我对EJB 3中Sessions Beans的功能感到好奇,以及它们是否可以在Spring的典型中型企业应用程序中被替换。

I found this article: http://drag0sd0g.blogspot.com/2010/01/session-bean-alternative-spring.html that states the following: "Because of heavy use of annotations, you can pretty much avoid “XML Hell” using EJB 3; the same cannot be said of Spring. Moreover, because it is an integral part of the Java EE standard, the EJB container is natively integrated with components such as JSF, JSP, servlets, the JTA transaction manager, JMS providers, and JAAS security providers of your application server. With Spring, you have to worry whether your application server fully supports the framework with these native components and other high-performance features like clustering, load balancing, and failover. If you aren't worried about such things, then Spring is not a bad choice at all" 我发现这篇文章: http//drag0sd0g.blogspot.com/2010/01/session-bean-alternative-spring.html声明如下: “由于大量使用注释,你几乎可以避免”XML Hell“使用EJB 3; Spring也不能这样说。而且,因为它是Java EE标准不可或缺的一部分,所以EJB容器本身与JSF,JSP,servlet,JTA事务管理器,JMS提供程序等组件集成在一起, 使用Spring,您必须担心您的应用程序服务器是否完全支持具有这些本机组件的框架以及其他高性能功能,如群集,负载平衡和故障转移。如果您不担心这样的事情,然后春天根本不是一个糟糕的选择“

Do you agree with this statement? 你是否同意这种说法? The Stateless Sessions Beans used to be considered a very powerful enterprise technology because of the pooling and management capabilities. 由于集合和管理功能,无状态会话Bean过去被认为是一种非常强大的企业技术。 My question is: when is it really necessary to use EJB 3 instead of or in addition to Spring (assuming a mission critical enterprise application in a large company)? 我的问题是:什么时候真的有必要使用EJB 3代替Spring或者除了Spring之外(假设在一家大公司中使用关键任务企业应用程序)?

Looks like yet another Java EE vs. Spring post... 看起来又是另一个Java EE vs. Spring帖子......

EJB/Java EE and Spring are now two mature, competitive Java-based technology stacks. EJB / Java EE和Spring现在是两个成熟,有竞争力的基于Java的技术堆栈。 Often there's no reason to complicate things and mix them up. 通常没有理由让事情复杂化并混淆起来。 EJB actually learned and used many ideas from Spring et al. EJB实际上学习并使用了Spring等人的许多想法。

Neither of them drives you into the XML/configuration hell. 他们都没有把你带入XML /配置地狱。 Both are fairly easy to get started with, at least with the very basic stuff. 两者都相当容易上手,至少对于非常基本的东西。

Spring is more than just IoC/SOA/transactions. Spring不仅仅是IoC / SOA /事务。 It's more like a toolbox - it's ready to integrate with, or directly provides, frameworks for ORM and transactions, web/MVC, security, timers/scheduling etc. You can pick exactly the pieces you need. 它更像是一个工具箱 - 它可以与ORM和事务,Web / MVC,安全性,定时器/调度等框架集成或直接提供。您可以精确选择所需的部分。 You're not forced to use a container (you can use it in your standalone "desktop" app). 您不必被迫使用容器(您可以在独立的“桌面”应用程序中使用它)。

EJB is part of Java EE stack. EJB是Java EE堆栈的一部分。 It is, well, the standard. 它是很好, 标准 It's not as broad, flexible as Spring, but it's by definition supported by all Java EE containers. 它不像Spring那样灵活,灵活,但根据定义,所有Java EE容器都支持它。

I prefer Spring for the freedom and being one step ahead. 我更喜欢春天的自由,领先一步。

I don't think there are many cases when the use of EJB 3 instead of Spring is absolutely necessary, but there are cases when using EJB 3 would be considerably easier. 我不认为有很多情况下使用EJB 3而不是Spring是绝对必要的,但是有些情况下使用EJB 3会相当容易。 As the article states, the main advantages of EJB is the integration with the various other JEE technologies and, as of EJB 3, Enterprise Beans are much simpler to write than in they were in previous versions of the spec. 正如文章所述,EJB的主要优点是与各种其他JEE技术的集成,并且从EJB 3开始,Enterprise Beans比以前版本的规范更容易编写。

The classic reason for using EJB over POJOs or other middleware technologies is transactions. 在POJO或其他中间件技术上使用EJB的经典原因是事务。 If your business logic needs to be transactional then EJB provides simple, declarative transnational demarcation and seamless integration with JTA via the container. 如果您的业务逻辑需要是事务性的,那么EJB提供简单的,声明性的跨国划分以及通过容器与JTA的无缝集成。 While the article suggests that support for clustering, load balancing and performance management is an advantage, this is very much dependant on your choice of JEE application server. 虽然本文建议支持群集,负载平衡和性能管理是一个优势,但这在很大程度上取决于您选择的JEE应用服务器。

I'd say the key factor in deciding whether to use Spring or EJB 3 is your container. 我说决定是否使用Spring或EJB 3的关键因素是你的容器。 If your target container is a fully JEE 5+ compliant application server and you need support for services such as transactions or messaging then EJB 3 is the obvious choice. 如果您的目标容器是完全符合JEE 5+的应用程序服务器,并且您需要支持事务或消息传递等服务,那么EJB 3是显而易见的选择。 If, however, you don't need to integrate with other JEE technologies or are deploying to a light-weight app server then using EJB would simply add unnecessary overhead. 但是,如果您不需要与其他JEE技术集成或部署到轻量级应用服务器,那么使用EJB只会增加不必要的开销。

How can anyone think EJB3's defining a data model using a series of java annotations spread out over several classes is superior to Hibernates simple model definition syntax is beyond me. 如何让人们认为EJB3使用一系列分散在几个类上的java注释来定义数据模型优于Hibernates简单模型定义语法超出我的范围。

Its a maintainability nightmare. 它是一个可维护性的噩梦。 Why have you got an intersection table? 为什么你有一个交叉表? It may be defined almost anywhere in the code base. 它几乎可以在代码库中的任何位置定义。 Some junior programmer plays with the annotations and now your java classes are out of sync with the actual database. 一些初级程序员使用注释,现在你的java类与实际的数据库不同步。

Got a performance issues (and you will). 遇到了性能问题(你会)。 Not only have you got the classic Hibernate "I don't know what SQL it's using" you also have the "I don't know why the table was built like that" problem. 你不仅拥有经典的Hibernate“我不知道它正在使用什么SQL”你还有“我不知道为什么桌子就像这样构建”的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM