This section covers what's new in Spring Framework 3.2. See also Appendix D, Migrating to Spring Framework 3.2
The Spring MVC programming model now provides explicit Servlet 3
@RequestMapping methods can
return one of:
complete processing in a separate thread managed by a task executor
within Spring MVC.
to complete processing at a later time from a thread not known to
Spring MVC — for example, in response to some external event (JMS,
to wrap a
Callable and customize the
timeout value or the task executor to use.
First-class support for testing Spring MVC applications with a
fluent API and without a Servlet container. Server-side tests involve use
DispatcherServlet while client-side REST
tests rely on the
RestTemplate. See Section 11.3.6, “Spring MVC Test Framework”.
ContentNeogtiationStrategy is now
available for resolving the requested media types from an incoming
request. The available implementations are based on the file extension,
query parameter, the 'Accept' header, or a fixed content type.
Equivalent options were previously available only in the
ContentNegotiatingViewResolver but are now available throughout.
ContentNegotiationManager is the central
class to use when configuring content negotiation options.
For more details see Section 17.15.4, “Configuring Content Negotiation”.
The introduction of
also enables selective suffix pattern matching for incoming requests.
For more details, see the Javadoc of
Classes annotated with
@ControllerAdvice can contain
@ModelAttribute methods and those will
@RequestMapping methods across
controller hierarchies as opposed to the controller hierarchy within which
they are declared.
@ControllerAdvice is a
component annotation allowing implementation classes to be auto-detected
through classpath scanning.
@MatrixVariable annotation adds
support for extracting matrix variables from the request URI. For more
details see the section called “Matrix Variables”.
An abstract base class implementation of the
WebApplicationInitializer interface is
provided to simplify code-based registration of a DispatcherServlet and
filters mapped to it. The new class is named
AbstractDispatcherServletInitializer and its
can be used with Java-based Spring configuration. For more details see
Section 17.14, “Code-based Servlet container initialization”.
A convenient base class with an
@ExceptionHandler method that handles
standard Spring MVC exceptions and returns a
ResponseEntity that allowing customizing and
writing the response with HTTP message converters. This servers as an
alternative to the
which does the same but returns a
See the revised Section 17.11, “Handling exceptions” including information on customizing the default Servlet container error page.
RestTemplate can now read an HTTP
response to a generic type (e.g.
are three new
exchange() methods that accept
ParameterizedTypeReference, a new class that
enables capturing and passing generic type info.
In support of this feature, the
HttpMessageConverter is extended by
GenericHttpMessageConverter adding a method
for reading content given a specified parameterized type. The new
interface is implemented by the
MappingJacksonHttpMessageConverter and also by a
Jaxb2CollectionHttpMessageConverter that can
read read a generic
Collection where the
generic type is a JAXB type annotated with
The Jackson JSON 2 library is now supported. Due to packaging
changes in the Jackson library, there are separate classes in Spring MVC
as well. Those are
MappingJackson2JsonView. Other related
configuration improvements include support for pretty printing as well as
JacksonObjectMapperFactoryBean for convenient
customization of an
ObjectMapper in XML
Tiles 3 is now supported in addition to Tiles 2.x. Configuring
it should be very similar to the Tiles 2 configuration, i.e. the
except using the
tiles3 instead of the
Also note that besides the version number change, the tiles
dependencies have also changed. You will need to have a subset or all of
@RequestBody or an
@RequestPart argument can now be followed
Errors argument making it possible to
handle validation errors (as a result of an
@Valid annotation) locally within the
@RequestBody now also supports a required
The HTTP request method
PATCH may now be used in
@RequestMapping methods as well as in the
RestTemplate in conjunction with Apache
HttpComponents HttpClient version 4.2 or later. The JDK
HttpURLConnection does not support the
Mapped interceptors now support URL patterns to be excluded. The MVC namespace and the MVC JavaConfig both expose these options.
As of 3.2, Spring allows for
@Value to be used as meta-annotations,
e.g. to build custom injection annotations in combination with specific qualifiers.
Analogously, you may build custom
e.g. in combination with specific qualifiers, @Lazy, @Primary, etc.
Spring provides a CacheManager adapter for JCache, building against the JCache 0.5 preview release. Full JCache support is coming next year, along with Java EE 7 final.
@DateTimeFormat annotation can
now be used without needing a dependency on the Joda Time library. If Joda
Time is not present the JDK
be used to parse and print date patterns. When Joda Time is present it
will continue to be used in preference to
It is now possible to define global formats that will be used when parsing and printing date and time types. See Section 7.7, “Configuring a global date & time format” for details.
In addition to the aforementioned inclusion of the Spring MVC Test Framework in
spring-test module, the Spring
TestContext Framework has been revised with support for
integration testing web applications as well as configuring application
contexts with context initializers. For further details, consult the
Spring Framework 3.2 includes fine-tuning of concurrent data structures in many parts of the framework, minimizing locks and generally improving the arrangements for highly concurrent creation of scoped/prototype beans.
Building and contributing to the framework has never been simpler with our move to a Gradle-based build system and source control at GitHub. See the building from source section of the README and the contributor guidelines for complete details.
Last but not least, Spring Framework 3.2 comes with refined Java 7 support within the framework as well as through upgraded third-party dependencies: specifically, CGLIB 3.0, ASM 4.0 (both of which come as inlined dependencies with Spring now) and AspectJ 1.7 support (next to the existing AspectJ 1.6 support).