An Unfair and Incomplete Comparison between Spring 3 Framework and Java EE 6


Facebook Twitter More...

By Markus Sprunck
; Revision: 1.2; Status: final; Last Content Change: Jan 29, 2013;

The first draft of this article had the title 'Spring & Java EE - Comparing Apples and Oranges'.

During writing this I learned that it is possible to compare Spring Framework and Java EE, but it is always an unfair and incomplete work.

Evolution of Java for Enterprise and Spring Framework 

The evolution of Java for Enterprise and Spring Framework are strongly connected to each other. Both leaned from each other and partly copied good concepts. In Table 1 you can see a simplified timeline with some key milestones of Java Platform for Enterprise and Spring Framework.

This table explains, that it makes only sense to compare Java EE v6 with Spring v3.0. Earlier versions of Spring Framework and J2EE are outdated and during writing this Java EE v7 is still not published (actually delayed to Q2 2013).

Table 1: Timeline of Java Platforms and Spring Framework
Year Java Platform, Standard Edition Java Platform, Enterprise Edition Spring Framework
Key 
Milestones
2000 J2SE v1.3



J2EE v1.2.1 


EJB 2 
- difficult deployment descriptors
- difficult testing
- lot of redundant artifacts
2001


J2SE v1.3



2002





2003 J2SE v1.4 J2EE v1.4



2004



Spring v1.0 First Spring Framework
- dependency injection (IoP)
- no Java EE application server
- competitor to J2EE
2005



Spring v1.2


2006 J2SE v5 Java EE v5 Spring v2.0 Java EE 5 (EJB 3.0)
- a lot of functions inspired by Spring
- elimination of component, home and remote interfaces
2007



Spring v2.5


2008





2009 Java SE v6 Java EE v6 Spring v3.0 Java EE 6 (EJB 3.1)
- interfaces are optional
- singleton beans
- cron-like scheduling
- embeddable containers
Spring 3.0
- Spring Expression Language
- MVC-Framework with improved REST support
2010





2011 Java SE v 7


Spring v 3.1



Building Blocks of Spring Framework

In table 2 the main building blocks of Spring Framework are listed. The Inversion of Control Container is the core function of Spring Framework. 

Table 2: Selected Building Blocks of the Spring v3.0 Framework
Inversion of Control Container - Inversion of Control
- Dependency Injection
- Configuration with XML files and/or annotations (auto wiring)
Model-View-Controller Framework - Domain objects (Models)
- Usually JSP templates (Views)
- DispatcherServlet as front-controller for Controller
Aspect-Oriented Programming Framework - Basic AOP for cross-cutting concerns in aspects
- Interception based and is configured at runtime
- Configuration with XML files and/or annotations
Batch Framework - Processing large volumes of records or tasks. Including: logging, tracing, transactions, job management, resource management, exception converting
Data Access Framework - Support is provided for popular frameworks
- JDBC, iBatis, Hibernate, JDO, JPA, Oracle TopLink, Apache OJB, and Apache Cayenne
Transaction Management Framework - Abstraction mechanism (JTA only supports nested transactions and global transactions, and requires an application server)
Remote Access Framework - Working with various RPC-based technologies available on the Java platform both for client connectivity and exporting objects on servers
Source & Further Reading: http://en.wikipedia.org/wiki/Spring_Framework 

Main Standards and Components of the Java Platform

In table 3 the main standards and components of the Java Platform, Enterprise Edition 6 are listed. This table makes clear that Java EE 6 contains of a lot of standards and is not just a framework.

Table 3: Selected Building Blocks of the Java EE 6 Architecture
Source of Picture The Java EE 6Tutorial, p39
Client Machine
- Java Server Faces (JSF 2.0)
- JSP Standard Tag Library (JSTL)
- Ajax with JavaServer Faces Technology
- Facelets (XHTML)
- Support for the Expression Language (EL)
- Templating for components and pages
- Java Servlet Technology (Servlet 3.0)
- Internationalizing and Localizing Web Applications
Java EE Server
- Enterprise JavaBeans (enterprise bean) components
- JAX-RS RESTful web services
- JAX-WS web service endpoints
- Enterprise Beans as POJO (Session and Message-driven)
- Managed Beans as POJO
- Interceptors
- Dependency Injection for Java (JSR 330)
- Contexts and Dependency Injection, CDI (JSR 299)
- Annotations to minimize deployment descriptor needs
- Asynchronous method invocation in session beans
- Declarative and programmatic security
- Java Message Service (JMS) API
- Java Persistence API entities
Persistance
- Java Database Connectivity API (JDBC)
- Java Persistence API 2.0
- Java EE Connector Architecture
- Java Transaction API (JTA)
Source & Further Reading: http://olex.openlogic.com/wazi/2010/get-started-with-jee6/

Practical Experiences

When I started to learn Spring Framework some years ago I implemented a small web application with a lot of Spring functions. To be honest, more than necessary for this task. This small application had extensive test code for unit and integration test automation. It has 100% line and branch coverage. Some time later, I decided to implement exactly the same application based on Java EE 6 Architecture to compare the two approaches. Both technologies worked well, have almost the same code size and a good maintainability.

One significant difference is the support of testing. Spring Framework has an excellent support for testing and Java EE 6 has here some weaknesses. For Java EE 6 you can use Embedded Glassfish, but this approach is annoying slow (long start-up time for embedded container) and touchy in the configuration.

A further outstanding feature of Spring Framework is the easy integration of legacy applications. It is easier to renew an old application in a step by step approach, e.g. with JDBC, transaction management and small parts of IoC in the beginning.

Conclusion

  • From the architectural point of view the models of Spring and Java EE are competitors. Depending on the strategy and constraints of your organization both show strengths and weaknesses. 
  • A combination of both can't generally be recommended, because it is either waste of the EJB Container functionality and/or difficult to maintain. In some selected cases, it may make sense to use Building Blocks of Spring Framework in a Java EE 6 application, e.g. Spring Batch, Data Access.
  • Spring Framework is not a standard - it is a product and an implementation of a framework. This means, there is no alternative vendor. Please, keep this always in mind.

Change History

 Revision  Date  Author  Description
 1.0  Apr 19, 2012  Markus Sprunck   first version
 1.1  July 31, 2012  Markus Sprunck  enhancements
 1.2  Jan 29, 2013  Markus Sprunck  picture added

Google+ Comments

You may press the +1 button to share and/or comment