Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring vs EJB (advantage and disadvantage) [duplicate]

I am currently preparing my final project study. I have to develop a distributed application for the management of human resources, but on my benchmark for technologies to use I found it confusing to decide between Spring or the EJB 3.1.

I do not know which will be the best suitable and easiest to use. I am a beginner for both technologies and therefore I hope so someone can help me.

like image 822
Informatique2015 Avatar asked Mar 16 '15 14:03

Informatique2015


People also ask

Which is better EJB or Spring?

The key difference between EJB and Spring is that EJB is a specification of Java EE while Spring is a framework or an implementation. Another key difference is that Spring does not support propagation of transaction context across remote calls while EJB does the same.

What is the difference between Spring and EJB?

Key Differences between EJB and Spring. EJB vs Spring's main difference is that EJB is a specification of Java EE, whereas Spring is a framework or an implementation. EJB is an architecture for transactional, component-based programming. It makes server-side development much easier for the Java developer.

Is spring alternative to EJB?

The Spring Framework is an application framework and IoC container for the Java platform. The framework was initially created as an alternative to EJB. Spring offers modular approach to adding new functionalities, which means that developers can use only parts they're interested in.

Is EJB still used 2021?

EJB is still there and growing up. There are many new features (SOAP/RESTful webservice, JPA entities, JAXB...)


1 Answers

You do not choose between EJB and Spring, you actually choose between Java EE and Spring because EJB is only a part of Java EE which includes also other components like JMS, Servlets, JSP, JSF, CDI, etc. In its early days (J2EE 1.4) programming model of enterprise edition of Java had a lot of flaws and deficiencies, but the most important ones were that it was tedious and verbose with a lot of boiler-plate code and tons of xml configurations. Spring was introduced as an alternative framework favoring convention-over-configuration principle. In other words, in Spring there were some sensible defaults that could be reconfigured if you need it. Java EE 5 introduced significant changes adopting the same convention-over-configuration principle from Spring, drastically reducing code amount and complexity required to get things going, so in this area Spring does not hold any sensible advantage any more.

It is also important to bear in mind that Java EE is just a specification. To build a real world app you need an implementation and there are plenty of them today - Glassfish, JBoss, TomcatEE, etc. all provide different implementations of Java EE specification introducing additional complexity - I mean, now you have to choose which Java EE implementation to choose. You can contrast that with Spring which comes from a single source.

Both frameworks gives you pretty much similar functionality. All support transactions, ORM, provide tools for building business logic, support CDI, AOP. In both Spring and Java EE you can only use the parts that you need, in other words you don't have to use the whole framework. You can even use them together - they can interoperate. Thanks to introduction of embeddable containers you now can even use Java EE features you need in areas like desktop applications which traditionally were the realm of Spring.

But one area where Java EE still lacks behind Spring is comfortable testability. It is not easy to write unit tests for EJB - for this you have to use a special third-party framework (Arquillian) and write some boilerplate code inside your tests (e.g. for building the test deployment package and deploying it onto the container, etc.). In fact, Java EE lacks any support for testing EJBs out of the box. In contrast, Spring is built with testability and TDD in mind. Testing Spring beans is easy since Spring includes bundled support for both testing (unit testing, integration testing) of all parts of the application as well as mocking.

like image 124
akhilless Avatar answered Oct 27 '22 23:10

akhilless