Session Beans and EJB3 vs Spring

I was curious about the features of Beans sessions in EJB 3 and whether they can be replaced in a typical mid-sized enterprise application using Spring.

I found this article: http://drag0sd0g.blogspot.com/2010/01/session-bean-alternative-spring.html which says the following: "Due to the heavy use of annotations, you can pretty much avoid XML Hell" "with EJB 3; the same cannot be said for Spring. Moreover, since it is an integral part of the Java EE standard, the EJB container is integrated with components such as JSF, JSP, servlets, transaction JTA manager, JMS providers and JAAS security providers your application server. With Spring you need to worry about whether your server supports fully app Nij framework with these native components and other high-end features, such as clustering, load balancing and failover. If you are not worried about such things, the Spring is not a bad choice at all

Do you agree with this statement? Beans-free sessions were considered very powerful enterprise technology because of the ability to integrate and manage. My question is: when is it really necessary to use EJB 3 instead of or in addition to Spring (assuming a critical enterprise application in a large company)?

+4
source share
3 answers

It looks like another Java EE vs. Spring post ...

EJB / Java EE and Spring are now two mature, competitive Java technology packages. Often there is no reason to complicate things and mix them. EJB really learned and used many ideas from Spring et al.

None of them lead you into an XML / configuration addon. Both are pretty easy to start with, at least from the element itself.

Spring is more than just IoC / SOA / transactions. This is more like a toolbar - it is ready to integrate or directly provides the infrastructure for ORM and transactions, web / MVC, security, timers / scheduling, etc. You can choose exactly the parts that you need. You should not use the container (you can use it in your standalone "desktop").

EJB is part of the Java EE stack. This is, well, standard. It is not as wide, flexible as Spring, but by definition it is supported by all Java EE containers.

I prefer Spring for freedom and one step ahead.

+7
source

I don’t think that there are many cases when using EJB 3 instead of Spring is absolutely necessary, but there are times when using EJB 3 will be much easier. As the article says, the main advantages of EJB are integration with various other JEE technologies, and with EJB 3 Enterprise Beans it is much easier to write than in previous versions of the specification.

The classic reason to use EJBs over POJOs or other middlewares is transactions. If your business logic needs to be transactional, EJB provides simple declarative cross-border demarcation and seamless integration with the JTA through the container. Although the article suggests that supporting clustering, load balancing, and performance management is an advantage, it really depends on your choice of JEE application server.

I would say that the key to deciding whether to use Spring or EJB 3 is your container. If your target container is fully compatible with the JEE 5+ application server and you need support for services such as transactions or messaging, then EJB 3 is the obvious choice. If, however, you do not need to integrate with other JEE technologies or deploy to a lightweight application server, then using EJB will simply add extra overhead.

+2
source

How would anyone think that EJB3 defining a data model using a series of java annotations distributed across several classes outperforms the syntax of the Hibernates simple syntax model.

Its a nightmare for maintainability. Why do you have an intersection table? It can be defined almost everywhere in the code base. Some junior programmers play with annotations, and now your Java classes do not synchronize with the actual database.

You have performance problems (and you will). You not only got the classic Hibernate β€œI don’t know what SQL it uses,” you also have the problem β€œI don’t know why this table was built like this.”

0
source

Source: https://habr.com/ru/post/1315723/


All Articles