About Markus Sprunck

Markus Sprunck works as senior software engineer and technical lead. In his free time he maintains the site Software Engineering Candies and experiments with different technologies and development paradigms.

Spring 3 and Java EE 6 – An unfair and incomplete comparison

The first draft of this small article had the title ‘Spring & Java EE – Comparing Apples and Oranges’. During writing this, I learnt that it is possible to compare Spring Framework and Java EE, but it is always an unfair and incomplete work.

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
2000J2SE v1.3

J2EE v1.2.1EJB 2
– difficult deployment descriptors
– difficult testing
– lot of redundantartifacts
2001J2SE v1.3
2002
2003J2SE v1.4J2EE v1.4
2004Spring v1.0First Spring Framework
– dependency injection (IoP)
– no Java EE application server
-competitor to J2EE
2005Spring v1.2
2006J2SE v5Java EE v5Spring v2.0Java EE 5 (EJB 3.0)
– a lot of functions inspired by Spring
– elimination of component, home and remote interfaces
2007Spring v2.5
2008
2009Java SE v6Java EE v6Spring v3.0Java 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
2011Java SE v 7Spring 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

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
Persistence
– 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 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.

Conclusion

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

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

2 Responses to "Spring 3 and Java EE 6 – An unfair and incomplete comparison"

  1. I recommend looking at TomEE and reconsider your article.

    • Daniel Kec says:

      Why? It’s just another app server with certified EJB container. I don’t see any need for reconsidering clever and balanced article

Leave a Reply


2 − one =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close