Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes EJB and other Java EE Technologies and the fly likes Arguments for EJB over Spring (or other lightweight containers) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Arguments for EJB over Spring (or other lightweight containers)" Watch "Arguments for EJB over Spring (or other lightweight containers)" New topic

Arguments for EJB over Spring (or other lightweight containers)

Charlie Fineman

Joined: Sep 02, 2005
Posts: 4
I, like many others, have drifted away from EJB after some early experience. Even before the advent of lightweight containers, I found myself finding other mechanisms for putting together distributed systems (largely because of the number of pieces I had to manage with the EJBs). I understand that EJB3 has made inroads into the number of artifacts required (via extensive use of annotations) but is it enough to make me take another look at EJB?

I'm curious what arguments the authors of EJB In Action would make to developers who have other options now. What does EJB offer over the competition these days? Why should I consider looking at it again?
Debu Panda
Ranch Hand

Joined: Jan 21, 2007
Posts: 100
I don't think it's EJB 3 vs Spring or Java EE vs Spring. Hoowevr like other EJB 3 books we have not closed our mind and preach EJB 3 and do not utter a word about Spring. We strongly believe It's about building effective applications using EJB 3 (or whatever ) technology makes sense to you?

Do you know that Spring has built integration with JPA and also implemented partial features of EJB 3 as part of Pitchfork project?

Our book is about EJB 3 and the Java Persistence API. It's about learning EJB 3 and effectively using it even if with Spring 2.0. We have covered in the cases when EJB 3 makes sense and suggest you to consider Spring when it's makes sense.

You can read the first chapter where we discuss why you would choose EJB 3

However you have to read the entire book


Author: EJB 3 In Action (
Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

If your application is depending on messaging or supporting distributed transactions originating from remote clinets, EJB is your amigo.
Reza Rahman
Ranch Hand

Joined: Feb 01, 2005
Posts: 580

As you can imagine, as an EJB 3 author it isn't really "politically correct" to talk about EJB 3 as a direct competitor to other technologies, particualrly Spring. As Debu hinted though, what technology stack you choose is largly dependent on what is important to you. Throughout the book, we've mentioned cases where EJB 3 has advantages, where Spring has advantages and where integrating both is a great idea. In short, EJB 3 definitely makes the EJB technolgy a viable choice again.

Here are some pros to using EJB 3:
1. As you mentioned, EJB 3 gets rid of the number of artifacts necessary for development.
2. With EJB 3, you have the option of using either XML or annotations, annotations being a lot less labor-intensive than verbose XML.
3. Becuase EJB is a total standards based platform, you get all enterprise services at your finger-tips without having to do a ton of configuration yourself (case in point--declarative transaction management in Spring vs. EJB3; another case in point, out of the box messaging, remoting and web services capabilities).
4. EJB 3 "seamlessly" (no pun intended) integrates with presenation tier technologies like JSF and Servlets.
5. Intelligent defaulting for most features makes enterprise development a lot of fun. This is generally not true of Spring.
6. A compelling state management model in stateful session beans. This is especially true if you are using JBoss seam.

Here are some strengths unique to Spring:
1. Much more robust AOP support.
2. If you make heavy use configuration through injecting collections, strings and so forth, Spring has better support for that.
3. Spring is more extensible if you happen to want to make changes to the container's behaviour or core functionality.
4. If you like tinkering with the nuts and bolts of a "container" or happen to have very complex application requirements, such as having fine-grained control over transactions, security, remoting, choice of persistence mechanism and so on, Spring is a better choice.

Hope this helps.

[ March 14, 2007: Message edited by: Reza Rahman ]

Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
I agree. Here's the link:
subject: Arguments for EJB over Spring (or other lightweight containers)
It's not a secret anymore!