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.

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

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


6 + = fifteen



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
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.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.