There are many discussion about Spring compared EJB 3.0. Here base on my developing experience, I share my humble opinion and some useful references.

1. Architecture difference:
-Spring advocates OOP and DDD
Using Spring the application usually adopts the Domain Model pattern that implements the business logic using good old fashioned object-oriented analysis and design techniques (OOAD). Most of project follow the Domain-Driven Design and
has the following roles: Entities, Value objects, Factories, Repositories, Services. Spring implements DI and AOP to simplify OOP design.

-EJB3 advocates Session Façade
Using EJB3 the application forces its components into three categories: session beans, entity beans, and message-driven beans even though in a typical object model there are classes that do not fall into one of these three categories. As
a result, many classes are unable to use the services provided by the EJB3 container.

Use a Session Façade to encapsulate business-tier components and expose a coarse-grained service to remote clients.
Clients access a Session Façade instead of accessing business components directly. Inside Session Facade you put the business logic and implement business object(domain object) as Entity bean.

2. Implementation difference:
– Spring is run out of JEE container
Spring is not an alternative for Java EE. Rather, it builds on top of Java EE, by making the JEE libraries less verbose to use, and by solving common programming errors. Spring actually supports EJB3 features, especially the nice Java Persistence API. Spring is not a package deal. You can use the IoC container without using Spring WEB MVC, for instance. You can choose to use the JpaTemplate , but you can also use the EJB3 Java Persistence API directly, by injecting an EntityManager. It´s all about choice.

– EJB3 is supported by JEE container
Despite EJB3 limitations, it is extremely likely that EJB 3 will be widely used for the simple reason that it is part of the J2EE standard. It is also important that EJB is an appropriate implementation technology for two types of applications: Applications that use distributed transactions initiated by remote clients. And applications that are heavily message-oriented and need message-driven beans.

Reference:
POJO Application Frameworks: Spring Vs. EJB 3.0
Make the Right Decision with Our Side-by-Side Comparison of Spring and EJB 3.0 part-I; part-II
J2EE design decision
Pro Spring: Spring and EJB

Something about domain model:
Domain Modeling – What exactly is a Rich Model ?
The relationship between the domain model and repositories

Advertisements