Spring Vs EJB ( A feature comparison)

By: Emiley J.  

In quite a few design brainstorming sessions, the debate between Spring and EJB results in a deadlock. There are developers who are damn passionate about Spring and hate EJBs. Let’s have a look at the main important differences between the two in terms of features they support.













Transaction management

  • Must use a JTA transaction manager.
  • Supports transactions that span remote method calls.
  • Supports multiple transaction environments through its PlatformTransactionManager interface, including JTA, Hibernate, JDO, and JDBC.
  • Does not natively support distributed transactions—it must be used with a JTA transaction manager.

Declarative transaction support

  • Can define transactions declaratively through the deployment descriptor.
  • Can define transaction behavior per method or per class by using the wildcard character *.
  • Cannot declaratively define rollback behavior—this must be done programmatically.
  • Can define transactions declaratively through the Spring configuration file or through class metadata.
  • Can define which methods to apply transaction behavior explicitly or by using regular expressions.
  • Can declaratively define rollback behavior per method and per exception type.


Supports programmatic bean-managed persistence and declarative container managed persistence.

Provides a framework for integrating with several persistence technologies, including JDBC, Hibernate, JDO, and iBATIS.

Declarative security

  • Supports declarative security through users and roles. The management and implementation of users and roles is container specific.
  • Declarative security is configured in the deployment descriptor.
  • No security implementation out-of-the box.
  • Acegi, an open source security framework built on top of Spring, provides declarative security through the Spring configuration file or class metadata.

Distributed computing

Provides container-managed remote method calls.

Provides proxying for remote calls via RMI, JAX-RPC, and web services.

Archived Comments

1. Good points you have covered here while comparing EJB and Spring.There are many differences you can
View Tutorial          By: pranit patil at 2017-09-14 07:01:53

2. I see your website needs some unique & fresh content.

Writing manually is time co

View Tutorial          By: WalkerCheryu at 2017-06-14 07:28:20

3. EJB's can be deployed on multiple servers and when they communicate togehter they can have one distr
View Tutorial          By: Tomek at 2011-09-12 12:29:07

4. Thanks for the Topic. But there are many more comparison to be done. What I love about Spring is it'
View Tutorial          By: Uditha Madumal at 2010-09-15 19:39:13

5. It seems author has half knowlage
EJB main Feture is Distributed Computing (as you can say ex

View Tutorial          By: Aryan Siddharth Singh Gautam at 2010-03-22 03:40:11

6. Thanks for this nice comparision table for Spring Vs EJB.
View Tutorial          By: guddu at 2009-10-17 03:08:59

Most Viewed Articles (in Java Beans )

Latest Articles (in Java Beans)

Comment on this tutorial