Wrapping It Up
In this article I've begun to compare the Spring application framework and the EJB 3.0 specification, focusing on support for persistence, transaction management, and statefulness. Interestingly both technologies address these issues well, and the commonalities underscore the validity of the comparison.
At this point I have illustrated some of the many similarities between Spring and EJB 3.0. The main differences observed have been state management, configurability, and extensibility.
If you are working with applications that are highly stateful then you may want to consider whether EJB 3.0 SFSBs might be a good solution. For highly conversational applications you may want to consider SEAM, which provides a very powerful solution for conversational interaction built on SFSBs and JSF.
Spring gives you more flexibility in many aspects of application development than EJB doesand as you've seen in this article, this is particularly true with regards to persistence and transaction providers. But the trade-off for this added flexibility is increased complexity in configuration. EJB 3.0 provides less flexibility but its tight technology stack, annotations-based configuration, and philosophy of configuration by exception make configuring EJB 3.0 applications quite simple. If flexibility is more important to you than a pre-defined approach then you certainly will want to consider Spring.
A final point on standardization: While Spring integrates many standards such as JTA, JDBC, and JMS it is not itself a Java standard. If standardization (and by extension vendor support, tooling, etc.) is important to your organization or application then you will want to consider EJB 3.0.
But luckily Spring and EJB 3.0 are not mutually exclusive choices. There are very powerful ways of integrating these two technologies to take advantage of their relative strengths and weaknesses. In part 2 in this series (coming soon) I will examine additional characteristics, including messaging, remoting, scheduling, dependency management, and intermediation. After the comparison is complete I will make some general observations that can assist in making a technical decision regarding Spring and EJB 3.0. And lastly, I will point out several strategies for integrating these technologies in order to take advantage of features of each technology.