spring-framework/spring-framework-reference/src/new-in-3.1.xml

277 lines
13 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<chapter id="new-in-3.1">
<title>New Features and Enhancements in Spring 3.1</title>
<para>Building on the support introduced in Spring 3.0, Spring 3.1 is
currently under development, and at the time of this writing Spring 3.1 M2
has just been released.</para>
<section id="new-in-3.1-features-overview">
<title>Overview of new features</title>
<para>This is a list of new features for Spring 3.1. Most features
do not yet have dedicated reference documentation but do have
Javadoc. In these cases, fully-qualified classnames are given.</para>
<section>
<title>Cache Abstraction</title>
<itemizedlist>
<listitem>
<para><xref linkend="cache"/></para>
</listitem>
<listitem>
<para><ulink
url="http://blog.springsource.com/2011/02/23/spring-3-1-m1-caching/">
Cache Abstraction</ulink> (SpringSource team blog)</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>Bean Definition Profiles</title>
<itemizedlist>
<listitem>
<para><ulink
url="http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/">
XML profiles</ulink> (SpringSource Team Blog)</para>
</listitem>
<listitem>
<para><ulink
url="http://blog.springsource.com/2011/02/14/spring-3-1-m1-introducing-profile/">
Introducing @Profile</ulink> (SpringSource Team Blog)</para>
</listitem>
<listitem>
<para>See org.springframework.context.annotation.Configuration Javadoc</para>
</listitem>
<listitem>
<para>See org.springframework.context.annotation.Profile Javadoc</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>Environment Abstraction</title>
<itemizedlist>
<listitem>
<para><ulink
url="http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/">
Environment Abstraction</ulink> (SpringSource Team Blog)</para>
</listitem>
<listitem>
<para>See org.springframework.core.env.Environment Javadoc</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>PropertySource Abstraction</title>
<itemizedlist>
<listitem>
<para><ulink
url="http://blog.springsource.com/2011/02/15/spring-3-1-m1-unified-property-management/">
Unified Property Management</ulink> (SpringSource Team Blog)</para>
</listitem>
<listitem>
<para>See org.springframework.core.env.Environment Javadoc</para>
</listitem>
<listitem>
<para>See org.springframework.core.env.PropertySource Javadoc</para>
</listitem>
<listitem>
<para>See org.springframework.context.annotation.PropertySource Javadoc</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>Code equivalents for Spring's XML namespaces</title>
<para>Code-based equivalents to popular Spring XML namespace elements such as
&lt;tx:annotation-driven/&gt; and &lt;mvc:annotation-driven&gt; have been
developed, in the form of <interfacename>@Enable</interfacename> annotations,
for use in conjunction with Spring's <interfacename>@Configuration</interfacename>
classes.</para>
<itemizedlist>
<listitem>
<para>See org.springframework.scheduling.annotation.Configuration Javadoc</para>
</listitem>
<listitem>
<para>See org.springframework.scheduling.annotation.EnableAsync Javadoc</para>
</listitem>
<listitem>
<para>See org.springframework.scheduling.annotation.EnableScheduling
Javadoc</para>
</listitem>
<listitem>
<para>See
org.springframework.scheduling.annotation.EnableTransactionManagement
Javadoc</para>
</listitem>
<listitem>
<para>See
org.springframework.scheduling.annotation.EnableLoadTimeWeaving
Javadoc</para>
</listitem>
<listitem>
<para>See org.springframework.scheduling.annotation.EnableWebMvc Javadoc</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>Builder-style APIs for code-based Hibernate configuration</title>
<para><classname>SessionFactoryBuilder</classname> and
<classname>AnnotationSessionFactoryBuilder</classname> classes have been designed
for use within <interfacename>@Bean</interfacename> methods in
<interfacename>@Configuration</interfacename> classes.</para>
<itemizedlist>
<listitem>
<para>See org.springframework.orm.hibernate3.SessionFactoryBuilder Javadoc</para>
</listitem>
<listitem>
<para>See
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBuilder
Javadoc</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>TestContext framework support for @Configuration classes and bean definition profiles</title>
<para>The <interfacename>@ContextConfiguration</interfacename> annotation now
supports supplying <interfacename>@Configuration</interfacename> classes for
configuring the Spring <classname>TestContext</classname>. In addition, a new
<interfacename>@ActiveProfiles</interfacename> annotation has been introduced
to support declarative configuration of active bean definition profiles in
<interfacename>ApplicationContext</interfacename> integration tests.</para>
<itemizedlist>
<listitem>
<para>See org.springframework.test.context.ContextConfiguration Javadoc</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>c: namespace for more concise constructor injection</title>
<itemizedlist>
<listitem>
<para><xref linkend="beans-c-namespace"/></para>
</listitem>
</itemizedlist>
</section>
<section>
<title>Support for injection against non-standard JavaBeans setters</title>
<para>Prior to Spring 3.1, in order to inject against a property method it had to
conform strictly to JavaBeans property signature rules, namely that any 'setter'
method must be void-returning. It is now possible in Spring XML to specify
setter methods that return any object type. This is useful when considering
designing APIs for method-chaining, where setter methods return a reference to
'this'.</para>
</section>
<section>
<title>Support for Servlet 3 code-based configuration of Servlet Container</title>
<para>The new <interfacename>WebApplicationInitializer</interfacename> builds atop
Servlet 3.0's <interfacename>ServletContainerInitializer</interfacename> support
to provide a programmatic alternative to the traditional web.xml.</para>
<itemizedlist>
<listitem>
<para>See org.springframework.web.WebApplicationInitializer Javadoc</para>
</listitem>
<listitem>
<para><ulink url="http://bit.ly/lrDHja">Diff from Spring's Greenhouse
reference application</ulink> demonstrating migration from web.xml to
<interfacename>WebApplicationInitializer</interfacename></para>
</listitem>
</itemizedlist>
</section>
<section>
<title>Support for Servlet 3 MultipartResolver</title>
<itemizedlist>
<listitem>
<para>See
org.springframework.web.multipart.support.StandardServletMultipartResolver
Javadoc</para>
</listitem>
</itemizedlist>
</section>
<section>
<title>JPA EntityManagerFactory bootstrapping without persistence.xml</title>
<para>In standard JPA, persistence units get defined through <literal>META-INF/persistence.xml</literal>
files in specific jar files which will in turn get searched for <literal>@Entity</literal> classes.
In many cases, persistence.xml does not contain more than a unit name and relies on defaults and/or
external setup for all other concerns (such as the DataSource to use, etc). For that reason, Spring 3.1
provides an alternative: <classname>LocalContainerEntityManagerFactoryBean</classname> accepts a
'packagesToScan' property, specifying base packages to scan for <literal>@Entity</literal> classes.
This is analogous to <classname>AnnotationSessionFactoryBean</classname>'s property of the same name
for native Hibernate setup, and also to Spring's component-scan feature for regular Spring beans.
Effectively, this allows for XML-free JPA setup at the mere expense of specifying a base package for
entity scanning: a particularly fine match for Spring applications which rely on component scanning
for Spring beans as well, possibly even bootstrapped using a code-based Servlet 3.0 initializer.</para>
</section>
<section>
<title>New HandlerMethod-based Support Classes For Annotated Controller Processing</title>
<para>Spring 3.1 introduces a new set of support classes for processing requests
with annotated controllers:</para>
<itemizedlist>
<listitem>RequestMappingHandlerMapping</listitem>
<listitem>RequestMappingHandlerAdapter</listitem>
<listitem>ExceptionHandlerExceptionResolver</listitem>
</itemizedlist>
<para>These classes are a replacement for the existing:</para>
<itemizedlist>
<listitem>DefaultAnnotationHandlerMapping</listitem>
<listitem>AnnotationMethodHandlerAdapter</listitem>
<listitem>AnnotationMethodHandlerExceptionResolver</listitem>
</itemizedlist>
<para>The new classes were developed in response to many requests to make
annotation controller support classes more customizable and open for extension.
Whereas previously you could configure a custom annotated controller method
argument resolver, with the new support classes you can customize the
processing for any supported method argument or return value type.</para>
<itemizedlist>
<listitem>See org.springframework.web.method.support.HandlerMethodArgumentResolver Javadoc</listitem>
<listitem>See org.springframework.web.method.support.HandlerMethodReturnValueHandler Javadoc</listitem>
</itemizedlist>
<para>A second notable difference is the introduction of a
<classname>HandlerMethod</classname> abstraction to represent an
<interface>@RequestMapping</interface> method. This abstraction is used
throughout by the new support classes as the <literal>handler</literal> instance.
For example a <classname>HandlerInterceptor</classname> can cast
the <literal>handler</literal> from <classname>Object</classname> to
<classname>HandlerMethod</classname> and get access to the target
controller method, its annotations, etc.</para>
<para>The new classes are enabled by default by the MVC namespace and by
Java-based configuration via <interface>@EnableWebMvc</interface>. The
existing classes will continue to be available but use of the new classes is
recommended going forward.</para>
</section>
<section>
<title>Consumes and Produces <interface>@RequestMapping</interface> Conditions</title>
<para>Improved support for specifying media types consumed by a method through the
<literal>'Content-Type'</literal> header as well as for producible types specified
through the <literal>'Accept'</literal> header.
See <xref linkend="mvc-ann-requestmapping-consumes"/> and
<xref linkend="mvc-ann-requestmapping-produces"/>
</para>
</section>
<section>
<title>Working With URI Template Variables In Controller Methods</title>
<para>@PathVariable method arguments are now automatically added to the model.
If you declare any <interface>@PathVariable</interface> arguments on a
controller method you no longer need to add them to the model.</para>
<para>Redirect view strings can now be URI templates.
For example a controller can return <literal>"redirect:/blog/{year}/{month}"</literal>.
The URI template will be expanded with variables from the model, which
of course includes <interface>@PathVariable</interface> method arguments
that are now automatically added to the model.</para>
<para>URI template variables are now included in data binding
in addition to request parameters, which are typically used for
populating a model.</para>
</section>
<section>
<title>Validation For <interface>@RequestBody</interface> Method Arguments</title>
<para>An <interface>@RequestBody</interface> method argument annotated
with <interface>@Valid</interface> is now automatically validated with the
same <classname>Validator</classname> instance used to validate
an <interface>@ModelAttribute</interface> method argument.
Both the MVC namespace and <interface>@EnableWebMvc</interface>
automatically configure a JSR-303 <classname>Validator</classname> adapter
provided a JSR-303 implementation is available on the classpath.</para>
</section>
</section>
</chapter>