Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use EJB3 or Spring for my business layer?

My team is developing a new service oriented product with a web front-end. In discussions about what technologies we will use we have settled on running a JBoss application server, and Flex frontend (with possible desktop deployment using Adobe AIR), and web services to interface the client and server.

We've reached an impasse when it comes to which server technology to use for our business logic. The big argument is between EJB3 and Spring, with our biggest concerns being scalability and performance, and also maintainability of the code base.

Here are my questions:

  1. What are the arguments for or against EJB3 vs Spring?
    • What pitfalls can I expect with each?
    • Where can I find good benchmark information?
like image 274
Justin Standard Avatar asked Sep 16 '08 01:09

Justin Standard


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.

Does anyone use EJB anymore?

EJB is still there and growing up. There are many new features (SOAP/RESTful webservice, JPA entities, JAXB...) depend on it or at least reuse the philosophy of developing.

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.

Can we use EJB with Spring?

However, it is important to note that using Spring does not prevent you from using EJBs. In fact, Spring makes it much easier to access EJBs and implement EJBs and functionality within them.


2 Answers

There won't be much difference between EJB3 and Spring based on Performance. We chose Spring for the following reasons (not mentioned in the question):

  • Spring drives the architecture in a direction that more readily supports unit testing. For example, inject a mock DAO object to unit test your business layer, or utilize Spring's MockHttpRequest object to unit test a servlet. We maintain a separate Spring config for unit tests that allows us to isolate tests to the specific layers.
  • An overriding driver was compatibility. If you need to support more than one App Server (or eventually want the option to move from JBoss to Glassfish, etc.), you will essentially be carrying your container (Spring) with you, rather than relying on compatibility between different implementations of the EJB3 specification.
  • Spring allows for technology choices for Persistence, object remoting, etc. For example, we are also using a Flex front end, and are using the Hessian protocol for communications between Flex and Spring.
like image 132
John Stauffer Avatar answered Oct 22 '22 07:10

John Stauffer


The gap between EJB3 and Spring is much smaller than it was, clearly. That said, one of the downsides to EJB3 now is that you can only inject into a bean, so you can end up turning components into beans that don't need to be.

The argument about unit testing is fairly irrelevant now - EJB3 is clearly designed to be more easily unit testable.

The compatibility argument above is also kind of irrelevant: whether you use EJB3 or Spring, you're still reliant on 3rd party-provided implementations of transaction managers, JMS, etc.

What would swing it for me, however, is support by the community. Working on an EJB3 project last year, there just weren't a lot of people out there using it and talking about their problems. Spring, rightly or wrongly, is extremely pervasive, particularlty in the enterprise, and that makes it easier to find someone who's got the same problem you're trying to solve.

like image 37
PEELY Avatar answered Oct 22 '22 07:10

PEELY