This is a single archived entry from Stefan Tilkov’s blog. For more up-to-date content, check out my author page at INNOQ, which has more information about me and also contains a list of published talks, podcasts, and articles. Or you can check out the full archive.

Java EE/EJB 3 vs. Spring

Stefan Tilkov,

I was collecting some opinions on when to choose Java EE over Spring (or vice versa). I know that one doesn’t have to choose, but I still believe most of the time only one of them (and not both) will become a core part of your architecture.

Here’s my preliminary list of resources:

I used the Spring IoC container once, and was very happy with it. I used EJB 2.x, and it sucked (but not as much as many claim), and EJB 3 is a vast improvement. I’m not leaning towards one or the other. At the moment, I see these main differences:

  • Spring is “just” a very well established open source project (with a huge community); Java EE/EJB 3 is “just” a standard supported by commercial and open source products
  • Spring relies heavily on XML configuration (yuck!) while Java EE/EJB 3 relies on annotations (phew!)
  • Spring can be stripped to its bare bones (cool!), with Java EE/EJB 3 you always get the whole “integrated” package (great!)

Any pointers to things I’m obviously missing?

On March 1, 2007 5:32 PM, Kevin Barfield said:

If you are comparing Spring to EJB 3, you really should take a look at the JBoss Seam framework. The latest version also provides Spring integration.

Yes, I do work for JBoss.


On March 1, 2007 5:45 PM, Stefan Tilkov said:

Very valid comment, unfortunately probably not applicable in my client’s particular situation (for non-technical reasons).

On March 1, 2007 6:15 PM, Arjen Poutsma said:

Well, I am biased, so I say use Spring :). But here are some remarks:

  1. 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. BEA´s WebLogic actually uses Spring to implement the EJB 3.0 interception and injection model. See

  2. 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.

  3. Spring does not “heavily rely” on using XML for configuration. It it the most popular format, but there are other formats, like Properties files, or the new Java configuration format, described here:

  4. One of the core ideas about Spring is that you keep it out of your architecture. Especially in the service layer and in your domain objects (the most important part of your application), you are not expected to use any Spring imports, or rely on Spring classes. Dependency Injection combined with externalized meta-data helps a lot with this true POJO style of development. In JEE, the two are often mixed because of the heavy usage of annotations (is an annotated object still a POJO?)

  5. Currently, there aren´t a lot of Java EE app servers out there. Sure, there is Glassfish, JBoss 5, and WebLogic 10, but most of them are not in their preview stages. And I think that IBM has not even announced its support for JEE 5 yet.



On August 18, 2007 8:34 AM, Eric said:

Most review that I’ve read lists Spring’s XML configuration as a negative factor and hail EJB 3’s annotation as an improvement. Weird, I like XML better than annotations. ;-) It must have something to do with the variety of legacy java apps that I maintain that don’t support annotation but it could also be because I like XML’s structured nature better. :-)