2.0.5
ApplicationContextResource interfaceResource implementationsResourceLoaderResourceLoaderAware interfaceResources as dependenciesResource pathsBeanWrapper, and PropertyEditorsAdvice types<tx:advice/> settings@Transactional@Transactional with AspectJSessionFactory setup in a Spring containerHibernateTemplateJpaDialectDispatcherServletMBeanInfoAssembler
InterfaceAutodetectCapableMBeanInfoAssembler
interfaceMethodNameBasedMBeanInfoAssemblerObjectNames for your beansutil schemajee schema<jee:jndi-lookup/> (simple)<jee:jndi-lookup/> (with single JNDI environment setting)<jee:jndi-lookup/> (with multiple JNDI environment settings)<jee:jndi-lookup/> (complex)<jee:local-slsb/> (simple)<jee:local-slsb/> (complex)<jee:remote-slsb/>lang schematx (transaction) schemaaop schematool schemabeans schemaspring-beans-2.0.dtdDeveloping software applications is hard enough even with good tools and technologies. Implementing applications using platforms which promise everything but turn out to be heavy-weight, hard to control and not very efficient during the development cycle makes it even harder. Spring provides a light-weight solution for building enterprise-ready applications, while still supporting the possibility of using declarative transaction management, remote access to your logic using RMI or web services, and various options for persisting your data to a database. Spring provides a full-featured MVC framework, and transparent ways of integrating AOP into your software.
Spring could potentially be a one-stop-shop for all your enterprise applications; however, Spring is modular, allowing you to use just those parts of it that you need, without having to bring in the rest. You can use the IoC container, with Struts on top, but you could also choose to use just the Hibernate integration code or the JDBC abstraction layer. Spring has been (and continues to be) designed to be non-intrusive, meaning dependencies on the framework itself are generally none (or absolutely minimal, depending on the area of use).
This document provides a reference guide to Spring's features. Since this document is still to be considered very much work-in-progress, if you have any requests or comments, please post them on the user mailing list or on the support forums at http://forum.springframework.org/.
Before we go on, a few words of gratitude are due to Christian Bauer (of the Hibernate team), who prepared and adapted the DocBook-XSL software in order to be able to create Hibernate's reference guide, thus also allowing us to create this one. Also thanks to Russell Healy for doing an extensive and valuable review of some of the material.
Java applications (a loose term which runs the gamut from constrained applets to full-fledged n-tier server-side enterprise applications) typically are composed of a number of objects that collaborate with one another to form the application proper. The objects in an application can thus be said to have dependencies between themselves.
The Java language and platform provides a wealth of functionality for architecting and building applications, ranging all the way from the very basic building blocks of primitive types and classes (and the means to define new classes), to rich full-featured application servers and web frameworks. One area that is decidedly conspicuous by its absence is any means of taking the basic building blocks and composing them into a coherent whole; this area has typically been left to the purvey of the architects and developers tasked with building an application (or applications). Now to be fair, there are a number of design patterns devoted to the business of composing the various classes and object instances that makeup an all-singing, all-dancing application. Design patterns such as Factory, Abstract Factory, Builder, Decorator, and Service Locator (to name but a few) have widespread recognition and acceptance within the software development industry (presumably that is why these patterns have been formalized as patterns in the first place). This is all very well, but these patterns are just that: best practices given a name, typically together with a description of what the pattern does, where the pattern is typically best applied, the problems that the application of the pattern addresses, and so forth. Notice that the last paragraph used the phrase “... a description of what the pattern does...”; pattern books and wikis are typically listings of such formalized best practice that you can certainly take away, mull over, and then implement yourself in your application.
The IoC component of the Spring Framework addresses the enterprise concern of taking the classes, objects, and services that are to compose an application, by providing a formalized means of composing these various disparate components into a fully working application ready for use. The Spring Framework takes best practices that have been proven over the years in numerous applications and formalized as design patterns, and actually codifies these patterns as first class objects that you as an architect and developer can take away and integrate into your own application(s). This is a Very Good Thing Indeed as attested to by the numerous organizations and institutions that have used the Spring Framework to engineer robust, maintainable applications.
The Spring Framework contains a lot of features, which are well-organized in seven modules shown in the diagram below. This chapter discusses each of the modules in turn.

Overview of the Spring Framework
The Core package
is the most fundamental part of the framework and provides the IoC and Dependency
Injection features. The basic concept here is the BeanFactory,
which provides a sophisticated implementation of the factory pattern which removes
the need for programmatic singletons and allows you to decouple the configuration and
specification of dependencies from your actual program logic.
The Context package build on the solid base provided by the Core package: it provides a way to access objects in a framework-style manner in a fashion somewhat reminiscent of a JNDI-registry. The context package inherits its features from the beans package and adds support for internationalization (I18N) (using for example resource bundles), event-propagation, resource-loading, and the transparent creation of contexts by, for example, a servlet container.
The DAO package provides a JDBC-abstraction layer that removes the need to do tedious JDBC coding and parsing of database-vendor specific error codes. Also, the JDBC package provides a way to do programmatic as well as declarative transaction management, not only for classes implementing special interfaces, but for all your POJOs (plain old Java objects).
The ORM package provides integration layers for popular object-relational mapping APIs, including JPA, JDO, Hibernate, and iBatis. Using the ORM package you can use all those O/R-mappers in combination with all the other features Spring offers, such as the simple declarative transaction management feature mentioned previously.
Spring's AOP package provides an AOP Alliance-compliant aspect-oriented programming implementation allowing you to define, for example, method-interceptors and pointcuts to cleanly decouple code implementing functionality that should logically speaking be separated. Using source-level metadata functionality you can also incorporate all kinds of behavioral information into your code, in a manner similar to that of .NET attributes.
Spring's Web package provides basic web-oriented integration features, such as multipart file-upload functionality, the initialization of the IoC container using servlet listeners and a web-oriented application context. When using Spring together with WebWork or Struts, this is the package to integrate with.
Spring's MVC package provides a Model-View-Controller (MVC) implementation for web-applications. Spring's MVC framework is not just any old implementation; it provides a clean separation between domain model code and web forms, and allows you to use all the other features of the Spring Framework.
With the building blocks described above you can use Spring in all sorts of scenarios, from applets up to fully-fledged enterprise applications using Spring's transaction management functionality and web framework integration.

Typical full-fledged Spring web application
By using Spring's
declarative transaction management features
the web application is fully transactional, just as it would be when using container
managed transactions as provided by Enterprise JavaBeans. All your custom business logic
can be implemented using simple POJOs, managed by Spring's IoC container. Additional
services include support for sending email, and validation that is independent of the
web layer enabling you to choose where to execute validation rules. Spring's ORM
support is integrated with JPA, Hibernate, JDO and iBatis; for example, when using
Hibernate, you can continue to use your existing mapping files and standard Hibernate
SessionFactory configuration. Form controllers seamlessly
integrate the web-layer with the domain model, removing the need for
ActionForms or other classes that transform HTTP parameters to
values for your domain model.

Spring middle-tier using a third-party web framework
Sometimes the current circumstances do not allow you to completely switch
to a different framework. The Spring Framework does not force
you to use everything within it; it is not an all-or-nothing
solution. Existing front-ends built using WebWork, Struts, Tapestry, or other UI
frameworks can be integrated perfectly well with a Spring-based middle-tier,
allowing you to use the transaction features that Spring offers. The only thing
you need to do is wire up your business logic using an
ApplicationContext and integrate your web layer using a
WebApplicationContext.

Remoting usage scenario
When you need to access existing code via web services, you can use Spring's
Hessian-, Burlap-, Rmi-
or JaxRpcProxyFactory classes. Enabling remote access to
existing applications suddenly is not that hard anymore.

EJBs - Wrapping existing POJOs
The Spring Framework also provides an access- and abstraction- layer for Enterprise JavaBeans, enabling you to reuse your existing POJOs and wrap them in Stateless Session Beans, for use in scalable, failsafe web applications that might need declarative security.
If you have been using the Spring Framework for some time, you will be aware that Spring has just undergone a major revision.
This revision includes a host of new features, and a lot of the existing functionality has been reviewed and improved. In fact, so much of Spring is shiny and improved that the Spring development team decided that the next release of Spring merited an increment of the version number; and so Spring 2.0 was announced in December 2005 at the Spring Experience conference in Florida.
This chapter is a guide to the new and improved features of Spring 2.0. It is intended to provide a high-level summary so that seasoned Spring architects and developers can become immediately familiar with the new Spring 2.0 functionality. For more in-depth information on the features, please refer to the corresponding sections hyperlinked from within this chapter.
Some of the new and improved functionality described below has been (or will be) backported into the Spring 1.2.x release line. Please do consult the changelogs for the 1.2.x releases to see if a feature has been backported.
One of the areas that contains a considerable number of 2.0 improvements is Spring's IoC container.
Spring XML configuration is now even easier, thanks to the advent of the new XML configuration syntax based on XML Schema. If you want to take advantage of the new tags that Spring provides (and the Spring team certainly suggest that you do because they make configuration less verbose and easier to read), then do read the section entitled Appendix A, XML Schema-based configuration.
On a related note, there is a new, updated DTD for Spring 2.0 that
you may wish to reference if you cannot take advantage of the XML Schema-based
configuration. The DOCTYPE declaration is included below for your convenience,
but the interested reader should definitely read the
'spring-beans-2.0.dtd' DTD included in the
'dist/resources' directory of the Spring
2.0 distribution.
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
Previous versions of Spring had IoC container level support for exactly two distinct bean scopes (singleton and prototype). Spring 2.0 improves on this by not only providing a number of additional scopes depending on the environment in which Spring is being deployed (for example, request and session scoped beans in a web environment), but also by providing integration points so that Spring users can create their own scopes.
It should be noted that although the underlying (and internal) implementation for singleton- and prototype-scoped beans has been changed, this change is totally transparent to the end user... no existing configuration needs to change, and no existing configuration will break.
Both the new and the original scopes are detailed in the section entitled Section 3.4, “Bean scopes”.
Not only is XML configuration easier to write, it is now also extensible.
What 'extensible' means in this context is that you, as an application developer, or (more likely) as a third party framework or product vendor, can write custom tags that other developers can then plug into their own Spring configuration files. This allows you to have your own domain specific language (the term is used loosely here) of sorts be reflected in the specific configuration of your own components.
Implementing custom Spring tags may not be of interest to every single application developer or enterprise architect using Spring in their own projects. We expect third-party vendors to be highly interested in developing custom configuration tags for use in Spring configuration files.
The extensible configuration mechanism is documented in Appendix B, Extensible XML authoring.
Spring 2.0 has a much improved AOP offering. The Spring AOP framework itself is markedly easier to configure in XML, and significantly less verbose as a result; and Spring 2.0 integrates with the AspectJ pointcut language and @AspectJ aspect declaration style. The chapter entitled Chapter 6, Aspect Oriented Programming with Spring is dedicated to describing this new support.
Spring 2.0 introduces new schema support for defining aspects backed by
regular Java objects. This support takes advantage of the AspectJ pointcut
language and offers fully typed advice (i.e. no more casting and
Object[] argument manipulation). Details of this support
can be found in the section entitled Section 6.3, “Schema-based AOP support”.
Spring 2.0 also supports aspects defined using the @AspectJ annotations. These aspects can be shared between AspectJ and Spring AOP, and require (honestly!) only some simple configuration. Said support for @AspectJ aspects is discussed in Section 6.2, “@AspectJ support”.
The way that transactions are configured in Spring 2.0 has been changed significantly. The previous 1.2.x style of configuration continues to be valid (and supported), but the new style is markedly less verbose and is the recommended style. Spring 2.0 also ships with an AspectJ aspects library that you can use to make pretty much any object transactional - even objects not created by the Spring IoC container.
The chapter entitled Chapter 9, Transaction management contains all of the details.
Spring 2.0 ships with a JPA abstraction layer that is similar in intent to Spring's JDBC abstraction layer in terms of scope and general usage patterns.
If you are interested in using a JPA-implementation as the backbone of your persistence layer, the section entitled Section 12.6, “JPA” is dedicated to detailing Spring's support and value-add in this area.
Prior to Spring 2.0, Spring's JMS offering was limited to
sending messages and the synchronous receiving of
messages. This functionality (encapsulated in the
JmsTemplate class) is great, but it doesn't
address the requirement for the asynchronous
receiving of messages.
Spring 2.0 now ships with full support for the reception of messages in an asynchronous fashion, as detailed in the section entitled Section 19.4.2, “Asynchronous Reception - Message-Driven POJOs”.
There are some small (but nevertheless notable) new classes in the
Spring Framework's JDBC support library. The first,
NamedParameterJdbcTemplate,
provides support for programming JDBC statements using named parameters (as
opposed to programming JDBC statements using only classic placeholder
('?') arguments.
Another of the new classes, the
SimpleJdbcTemplate,
is aimed at making using the JdbcTemplate even easier to use when
you are developing against Java 5+ (Tiger).
The web tier support has been substantially improved and expanded in Spring 2.0.
A rich JSP tag library for Spring MVC was the JIRA issue that garnered the most votes from Spring users (by a wide margin).
Spring 2.0 ships with a full featured JSP tag library that makes the job of authoring JSP pages much easier when using Spring MVC; the Spring team is confident it will satisfy all of those developers who voted for the issue on JIRA. The new tag library is itself covered in the section entitled Section 13.9, “Using Spring's form tag library”, and a quick reference to all of the new tags can be found in the appendix entitled Appendix E, spring-form.tld.
For a lot of projects, sticking to established conventions and
having reasonable defaults is just what the projects need...
this theme of convention-over-configuration now has explicit support in
Spring MVC. What this means is that if you establish a set of naming
conventions for your Controllers and views, you can
substantially cut down on the amount of XML configuration
that is required to setup handler mappings, view resolvers,
ModelAndView instances, etc. This is a great boon
with regards to rapid prototyping, and can also lend a degree of (always
good-to-have) consistency across a codebase.
Spring MVC's convention-over-configuration support is detailed in the section entitled Section 13.11, “Convention over configuration”
Spring 2.0 ships with a Portlet framework that is conceptually similar to the Spring MVC framework. Detailed coverage of the Spring Portlet framework can be found in the section entitled Chapter 16, Portlet MVC Framework.
This final section outlines all of the other new and improved Spring 2.0 features and functionality.
Spring 2.0 now has support for beans written in languages other than Java, with the currently supported dynamic languages being JRuby, Groovy and BeanShell. This dynamic language support is comprehensively detailed in the section entitled Chapter 24, Dynamic language support.
The Spring Framework now has support for Notifications;
it is also possible to exercise declarative control over the registration
behavior of MBeans with an MBeanServer.
Spring 2.0 offers an abstraction around the scheduling of tasks.
For the interested developer, the section entitled Section 23.4, “The Spring TaskExecutor abstraction”
contains all of the details.
Find below pointers to documentation describing some of the new Java 5 support in Spring 2.0.