• Starting goal of Spring (from 2002) was to help to reduce the complexity
of J2EE development & to simplify without sacrificing power
• It grew from practical experience of Rod Johnson & his ilk as they found
J2EE has become extremely complex to use.
• As the leading full-stack Java/Java EE application framework, Spring
delivers significant benefits for many projects, reducing development
effort and costs while improving test coverage and quality.
• It is a non-harvesting framework (as told by Martin Fowler) & delivers
• Spring makes developing J2EE application easier, Introduced by Rod
Johnson in “J2EE Design & Development”
• Rod Johnson started developing framework for web application in 2000
while working as independent consultant in the financial industry in
• This project (as Spring) was started by Rod Johnson in 2002 but the first
official release was made in March 2004
• The first version was written by Rod Johnson, who first released it with
the publication of his book Expert One-on-One Java EE Design and
Development (Wrox Press, October 2002). He also wrote a book J2EE
without EJB in 2003
• Now spring is officially developed & maintained by interface21 company
• Spring has crossed 1 million downloads as of 22/09/2006
We can believe that,
• “Spring framework” of the developers, by the developers & for the
developers shall not perish from java world
Goals (Outlined by Rod
• J2EE should be easier to use currently Over-engineering is endemic in
• It's best to program to interfaces, rather than classes. Spring reduces the
complexity cost of using interfaces to zero.
• POJO offer a great way of configuring applications & it should be utilized
• OO design is more important than any implementation technology, such
• Checked exceptions are overused in Java. A framework shouldn't force
you to catch exceptions you're unlikely to be able to recover from.
• J2EE can be made simpler without sacrificing power & facilitate best
• Testability is essential, and a framework such as Spring should help make
your code easier to test.
• Spring should be a pleasure to use
• Application code should not depend on Spring APIs
• Spring should not compete with good existing solutions, but should foster
integration. (For example, JDO and Hibernate are great O/R mapping
solutions. We don't need to develop another one.)
• Enable applications to use POJO’s & allow enterprise services to be
applied to those POJOs in a declarative, non-invasive way
• addresses overall application architecture & can become internal structure
of an application
• focuses on consistent programming model & decouples from concrete
runtime environment hence boosting testing
• It intends support any kind of Java application (Spring has even
extensions to SWING) but with special support for J2EE environments
J2EE Architectural benefits &
• Declarative Transactions
o Good, but not always appropriate
o Best choice, there are equally good alternatives & also can be a made
o Entity and SFSB have weak implementations. Session replication
works well only in theory.
o Scaling is more important at the web layer… Ex: eBay, Yahoo!, Google
• Resource Management
o Not tied container (Heavy weight one)
o Security requirements tend to be more complex in practice
• Business Object Management
o Use of JNDI unnecessarily complex with very less value addition
• Distributed transaction with multiple data sources
o EJB - still the best choice
Co-location of state & behavior is the lynch-pin of scalable performance
So move as little as possible as rarely as possible.
"Transparency is valuable, but while many things can be made transparent in distrubted objects,
performance isn't usually one of them" - Martin Fowler Errant Architectures
• Thread Management
o Multi-threaded services without read/write instance variables are
scaling well (i.e. Servlets).
• Instance Pooling
o Is over-valued theory with modern garbage collectors.
• Google, Yahoo*, eBay & Amazon are scaling well because of stateless
Spring is Non-Invasive
What does that mean?
• You are not forced to import or extend any Spring APIs
• An invasive API takes over your code. Introduces noise & boilerplate code
• Anti-patterns: (Sample Invasive framework)
o EJB forces you to use JNDI
o Struts forces you to extend Action, ActionForm
Invasive frameworks are inherently difficult to test (especially unit testing).
You have to stub the runtime that is supplied by the application server
Spring core aspects
At it’s core, Spring provides:
• An Inversion of Control Container
o Also known as Dependency Injection (Fowler’s term)
• An AOP Framework
o Spring provides a proxy-based AOP framework
o You can alternatively integrate with AspectJ or AspectWerkz
• A Service Abstraction Layer
o Consistent integration with various standard and 3rd party APIs
These together enable you to write powerful, scalable applications using
IoC & Dependency Injection
IoC or Dependency Injection
IoC or Dependency Injection
Inversion of Control (IoC) is all about Object dependencies.
Traditional "Pull" approach:
• Direct instantiation (Ex: new Person())
• Asking a Factory for an implementation (PersonFactory.getPerson())
• Looking up a service via JNDI (Naming.lookup())
• Something outside of the Object "pushes" its dependencies into it.
• This is usually done through XML configuration or Java annotations
This “Push” approach is called “Dependency Injection”
IOC - Definitions
• Dependency Injection is the act of injecting dependencies into an Object.
• Inversion of Control is the general style of using Dependency Injection to
wire together application layers.
• A way of sorting out dependencies between objects and
automatically “injecting” references to collaborating objects on demand
• Spring is an Inversion of Control container. That is, it is a container that handles
Dependency Injection for you. Powerful bean configuration management (IOC) is
the most important feature provided by Spring
Why Dependency Injection?
• Loose Coupling & High Cohesion
o It is loosely Coupled because you don't hard-code dependencies
between layers and modules. Instead you configure them outside of
the code. This makes it easy to swap in a new implementation of a
service, or break off a module and reuse it elsewhere, although they
are loosely coupled it is easy to wire them
o It reduces coupling between implementation objects and encourages
interface based design
o Promotes OO design, allows pluggability, hot swapping & reuse
o Testability is improved because your Objects don't know or care what
environment they're in as long as someone injects their dependencies.
Hence you can deploy Objects into a test environment and inject Mock
Objects for their dependencies with ease.
• Martin Fowler came up with this idea of dependency injection
• Follows the DRY (Don’t Repeat Yourself) principle
• Probably the most important feature of Spring, the main driving factor for
• Show cases the philosophy & techniques of Spring
• Don’t compete with best
• Provides abstraction & fully-factored API wrappers over these
Remote calls and Web Services (Axis)
AOP (AspectJ) & declarative transaction support
Spring Related Add-Ons
• ACEGI Security - Full fledged security services for the Spring Framework
• Spring IDE - IDE (Eclipse plug in) the configuration files used by the Spring
• Spring BeanDoc - tool that facilitates documentation and graphing of Spring bean
factories and application context files
• XDoclet Spring Tags - support for generating Spring XML config files from
annotations in Java classes (JDK1.5 annotations can be used to achieve this)
• AppFuse is Matt Raible's project to start your web projects. It uses Spring at it's
Road Ahead – Final thoughts
Spring in 2008 – Road Ahead
On brighter side
• Weblogic full fledged support – Good news, official vendor support will
• Enormous # of Spring developers (Struts became popular for this reason,
so popularity may not be always because of technical excellence) & hence
lot of Spring jobs
• Committed & highly intelligent Spring core team
• Spring Webflow has good support for continuations
• Good support for JSF/OSGI
• Spring metadata or XML hell
• EJB 3 which is lightweight & has come up with same value
proposition backed by strong vendors
• Seam, RIFE & Ruby on Rails – Competing frameworks, also by
highly credible set of people
• Java EE & adaptation by Strong vendors like Oracle, IBM, JBoss,
• Vista & .NET innovation, Support for AJAX, Scripting langauages
• Guice framework (Dependency Injection) from Google
• Spring in Action - by Craig Walls and Ryan Breidenbach
• Pro Spring - by Rob Harrop and Jan Machacek
• J2EE Without EJB - by Rod Johnson and Juergen Holler
• Expert One-on-One J2EE Design and Development - by Rod Johnson
• Spring Developers Notebook - by Bruce Tate and Justin Gehtland
• Spring Live - by Matt Raible
• Professional Java Development with the Spring Framework - Rod Johnson
• Much of the content in this presentation is influenced by presentation
from Rod,books and links (see reference)
• Coming up?
o Scheduling Jobs with Spring and Quartz?
o Working with LDAP & Spring?
o Working with JMX & Spring
o Sending Email with Spring & velocity?
o Working with JDBC using Spring?
o Working with Hibernate using Spring?
o Working with iBatis using spring Spring?
o Working with Hibernate using Spring?
o Working with EJB using Spring?
o Accessing Web Services Via Spring?
o Exposing a Web Service with Spring?
o Integrating Spring with JSF/Struts/Webwork/Tapestry?
o Working with Swing (RCP) & Spring?
Questions? Suggestions? Please mail me