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 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 redundantartifacts
|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
|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
|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 Expression Language
– MVC-Framework with improved REST support
|2011||Java SE v 7||Spring v 3.1|
So, in table 2 the main building blocks of Spring Framework are listed. The Inversion of Control Container is the core function of Spring Framework. To understand how this works you may also check A minimal Java application based on Spring framework(sample code uses Spring 2.5.6.A, but the main principles are the same for Spring 3.0).
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
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
– 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
– 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
– 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/
When I started to learn Spring Framework 3.0 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.
- Form 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.
Reference: Lightweight Java Enterprise Architectures – An Unfair and Incomplete Comparison Between Spring 3 Framework and Java EE 6 from our JCG partner Markus Sprunck at the Software Engineering Candies blog.