Browse Source
This commit adds documentation to the "New Features and Enhancements in Spring 3.2" section of the reference manual regarding new testing features. Issue: SPR-9941pull/202/head
1 changed files with 257 additions and 220 deletions
@ -1,225 +1,262 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||||
<chapter xml:id="new-in-3.2" |
<chapter version="5.0" |
||||||
xmlns="http://docbook.org/ns/docbook" version="5.0" |
xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd" |
||||||
xmlns:xl="http://www.w3.org/1999/xlink" |
xml:id="new-in-3.2" xmlns="http://docbook.org/ns/docbook" |
||||||
xmlns:xi="http://www.w3.org/2001/XInclude" |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
xmlns:xs="http://www.w3.org/2001/XMLSchema" |
||||||
xsi:schemaLocation=" |
xmlns:xl="http://www.w3.org/1999/xlink" |
||||||
http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd |
xmlns:xi="http://www.w3.org/2001/XInclude" |
||||||
http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"> |
xmlns:ns="http://docbook.org/ns/docbook"> |
||||||
<title>New Features and Enhancements in Spring 3.2</title> |
<title>New Features and Enhancements in Spring 3.2</title> |
||||||
|
|
||||||
<section xml:id="new-in-3.2-features-overview"> |
<section xml:id="new-in-3.2-webmvc-async"> |
||||||
<title>Overview of new features</title> |
<title>Support for Servlet 3 based asynchronous request processing</title> |
||||||
|
|
||||||
<section xml:id="new-in-3.2-webmvc-async"> |
<para>The Spring MVC programming model now provides explicit Servlet 3 |
||||||
<title>Support for Servlet 3 based asynchronous request processing</title> |
async support. <interfacename>@RequestMapping</interfacename> methods can |
||||||
|
return one of:</para> |
||||||
<para>The Spring MVC programming model now provides explicit Servlet 3 async support. |
|
||||||
<interfacename>@RequestMapping</interfacename> methods can return one of:</para> |
<itemizedlist> |
||||||
|
<listitem> |
||||||
<itemizedlist> |
<para><interfacename>java.util.concurrent.Callable</interfacename> to |
||||||
<listitem> |
complete processing in a separate thread managed by a task executor |
||||||
<para><interfacename>java.util.concurrent.Callable</interfacename> to |
within Spring MVC.</para> |
||||||
complete processing in a separate thread managed by a task executor |
</listitem> |
||||||
within Spring MVC.</para> |
|
||||||
</listitem> |
<listitem> |
||||||
<listitem> |
<para><classname>org.springframework.web.context.request.async.DeferredResult</classname> |
||||||
<para><classname>org.springframework.web.context.request.async.DeferredResult</classname> |
to complete processing at a later time from a thread not known to |
||||||
to complete processing at a later time from a thread not known to |
Spring MVC — for example, in response to some external event (JMS, |
||||||
Spring MVC, e.g. in response to some external event (JSM, AMQP, etc.)</para> |
AMQP, etc.)</para> |
||||||
</listitem> |
</listitem> |
||||||
<listitem> |
|
||||||
<para><classname>org.springframework.web.context.request.async.AsyncTask</classname> |
<listitem> |
||||||
to wrap a <interfacename>Callable</interfacename> and |
<para><classname>org.springframework.web.context.request.async.AsyncTask</classname> |
||||||
customize the timeout value or the task executor to use.</para> |
to wrap a <interfacename>Callable</interfacename> and customize the |
||||||
</listitem> |
timeout value or the task executor to use.</para> |
||||||
</itemizedlist> |
</listitem> |
||||||
|
</itemizedlist> |
||||||
<para>See <link |
|
||||||
xl:href="http://blog.springsource.org/2012/05/06/spring-mvc-3-2-preview-introducing-servlet-3-async-support/"> |
<para>See <link |
||||||
Introducing Servlet 3 Async Support</link> (SpringSource team blog).</para> |
xl:href="http://blog.springsource.org/2012/05/06/spring-mvc-3-2-preview-introducing-servlet-3-async-support/"> |
||||||
|
Introducing Servlet 3 Async Support</link> (SpringSource team |
||||||
</section> |
blog).</para> |
||||||
|
</section> |
||||||
<section xml:id="new-in-3.2-spring-mvc-test"> |
|
||||||
<title>Spring MVC Test framework</title> |
<section xml:id="new-in-3.2-spring-mvc-test"> |
||||||
|
<title>Spring MVC Test framework</title> |
||||||
<para>First-class support for testing Spring MVC applications with a |
|
||||||
fluent API and without a servlet container. Server-side tests involve |
<para>First-class support for testing Spring MVC applications with a |
||||||
use of the <classname>DispatcherServlet</classname> while client-side |
fluent API and without a Servlet container. Server-side tests involve use |
||||||
REST tests rely on the <classname>RestTemplate</classname>. |
of the <classname>DispatcherServlet</classname> while client-side REST |
||||||
See <xref linkend="spring-mvc-test-framework"/>. |
tests rely on the <classname>RestTemplate</classname>. See <xref |
||||||
</para> |
linkend="spring-mvc-test-framework" />.</para> |
||||||
|
</section> |
||||||
</section> |
|
||||||
|
<section xml:id="new-in-3.2-webmvc-content-negotiation"> |
||||||
<section xml:id="new-in-3.2-webmvc-content-negotiation"> |
<title>Content negotiation improvements</title> |
||||||
<title>Content negotiation improvements</title> |
|
||||||
|
<para>A <interfacename>ContentNeogtiationStrategy</interfacename> is now |
||||||
<para>A <interfacename>ContentNeogtiationStrategy</interfacename> is now |
available for resolving the requested media types from an incoming |
||||||
available for resolving the requested media types from an incoming request. |
request. The available implementations are based on path extension, |
||||||
The available implementations are based on path extension, request parameter, |
request parameter, 'Accept' header, and a fixed default content type. |
||||||
'Accept' header, and a fixed default content type. Equivalent options were |
Equivalent options were previously available only in the |
||||||
previously available only in the ContentNegotiatingViewResolver but are now |
ContentNegotiatingViewResolver but are now available throughout.</para> |
||||||
available throughout.</para> |
|
||||||
|
<para><classname>ContentNegotiationManager</classname> is the central |
||||||
<para><classname>ContentNegotiationManager</classname> is the central class to |
class to use when configuring content negotiation options. It accepts one |
||||||
use when configuring content negotiation options. It accepts one or |
or more ContentNeogtiationStrategy instances and delegates to them. It can |
||||||
more ContentNeogtiationStrategy instances and delegates to them. It can be |
be plugged into <classname>RequestMappingHandlerMapping</classname>, |
||||||
plugged into <classname>RequestMappingHandlerMapping</classname>, |
<classname>RequestMappingHandlerAdapter</classname>, |
||||||
<classname>RequestMappingHandlerAdapter</classname>, |
<classname>ExceptionHandlerExceptionResolver</classname>, and |
||||||
<classname>ExceptionHandlerExceptionResolver</classname>, |
<classname>ContentNegotiatingViewResolver</classname>. The MVC namespace |
||||||
and <classname>ContentNegotiatingViewResolver</classname>. The MVC |
and the MVC JavaConfig provide convenient options to configure all |
||||||
namespace and the MVC Java config provide convenient options to configure |
that.</para> |
||||||
all that.</para> |
|
||||||
|
<para>The introduction of <classname>ContentNegotiationManger</classname> |
||||||
<para>The introduction of <classname>ContentNegotiationManger</classname> |
also enables smart suffix pattern matching for incoming requests. See |
||||||
also enables smart suffix pattern matching for incoming requests. |
<link |
||||||
See <link xl:href="https://github.com/SpringSource/spring-framework/commit/4fd7645"> |
xl:href="https://github.com/SpringSource/spring-framework/commit/4fd7645">commit |
||||||
commit message</link></para> |
message.</link></para> |
||||||
|
</section> |
||||||
</section> |
|
||||||
|
<section xml:id="new-in-3.2-webmvc-controller-advice"> |
||||||
<section xml:id="new-in-3.2-webmvc-controller-advice"> |
<title><interfacename>@ControllerAdvice</interfacename> annotation</title> |
||||||
<title><interfacename>@ControllerAdvice</interfacename> annotation</title> |
|
||||||
|
<para>Classes annotated with |
||||||
<para>Classes annotated with <interfacename>@ControllerAdvice</interfacename> |
<interfacename>@ControllerAdvice</interfacename> can contain |
||||||
can contain <interfacename>@ExceptionHandler</interfacename>, |
<interfacename>@ExceptionHandler</interfacename>, |
||||||
<interfacename>@InitBinder</interfacename>, and |
<interfacename>@InitBinder</interfacename>, and |
||||||
<interfacename>@ModelAttribute</interfacename> methods and those will apply |
<interfacename>@ModelAttribute</interfacename> methods and those will |
||||||
to <interfacename>@RequestMapping</interfacename> methods across controller |
apply to <interfacename>@RequestMapping</interfacename> methods across |
||||||
hierarchies as opposed to the controller hierarchy within which they are declared. |
controller hierarchies as opposed to the controller hierarchy within which |
||||||
<interfacename>@ControllerAdvice</interfacename> is |
they are declared. <interfacename>@ControllerAdvice</interfacename> is a |
||||||
a component annotation allowing implementation classes to be auto-detected |
component annotation allowing implementation classes to be auto-detected |
||||||
through classpath scanning.</para> |
through classpath scanning.</para> |
||||||
|
</section> |
||||||
</section> |
|
||||||
|
<section xml:id="new-in-3.2-matrix-variables"> |
||||||
<section xml:id="new-in-3.2-matrix-variables"> |
<title>Matrix variables</title> |
||||||
<title>Matrix variables</title> |
|
||||||
|
<para>A new <interfacename>@MatrixVariable</interfacename> annotation adds |
||||||
<para>A new <interfacename>@MatrixVariable</interfacename> annotation |
support for extracting matrix variables from the request URI. For more |
||||||
adds support for extracting matrix variables from the request URI. |
details see <xref linkend="mvc-ann-matrix-variables" />.</para> |
||||||
For more details see <xref linkend="mvc-ann-matrix-variables"/>.</para> |
</section> |
||||||
</section> |
|
||||||
|
<section xml:id="new-in-3.2-dispatcher-servlet-initializer"> |
||||||
<section xml:id="new-in-3.2-dispatcher-servlet-initializer"> |
<title>Abstract base class for code-based Servlet 3+ container |
||||||
<title>Abstract base class for code-based Servlet 3+ container initialization</title> |
initialization</title> |
||||||
|
|
||||||
<para>An abstract base class implementation of the |
<para>An abstract base class implementation of the |
||||||
<interfacename>WebApplicationInitializer</interfacename> interface is provided to |
<interfacename>WebApplicationInitializer</interfacename> interface is |
||||||
simplify code-based registration of a DispatcherServlet and filters |
provided to simplify code-based registration of a DispatcherServlet and |
||||||
mapped to it. The new class is named |
filters mapped to it. The new class is named |
||||||
<classname>AbstractDispatcherServletInitializer</classname> and its |
<classname>AbstractDispatcherServletInitializer</classname> and its |
||||||
sub-class <classname>AbstractAnnotationConfigDispatcherServletInitializer</classname> |
sub-class |
||||||
can be used with Java-based Spring configuration. |
<classname>AbstractAnnotationConfigDispatcherServletInitializer</classname> |
||||||
For more details see <xref linkend="mvc-container-config"/>.</para> |
can be used with Java-based Spring configuration. For more details see |
||||||
</section> |
<xref linkend="mvc-container-config" />.</para> |
||||||
|
</section> |
||||||
<section xml:id="new-in-3.2-webmvc-exception-handler-support"> |
|
||||||
<title><classname>ResponseEntityExceptionHandler</classname> class</title> |
<section xml:id="new-in-3.2-webmvc-exception-handler-support"> |
||||||
|
<title><classname>ResponseEntityExceptionHandler</classname> class</title> |
||||||
<para>A convenient base class with an |
|
||||||
<interfacename>@ExceptionHandler</interfacename> |
<para>A convenient base class with an |
||||||
method that handles standard Spring MVC exceptions and returns a |
<interfacename>@ExceptionHandler</interfacename> method that handles |
||||||
<classname>ResponseEntity</classname> that allowing customizing and writing |
standard Spring MVC exceptions and returns a |
||||||
the response with HTTP message converters. This servers as an alternative |
<classname>ResponseEntity</classname> that allowing customizing and |
||||||
to the <classname>DefaultHandlerExceptionResolver</classname>, which does |
writing the response with HTTP message converters. This servers as an |
||||||
the same but returns a <classname>ModelAndView</classname> instead.</para> |
alternative to the <classname>DefaultHandlerExceptionResolver</classname>, |
||||||
|
which does the same but returns a <classname>ModelAndView</classname> |
||||||
<para>See the revised <xref linkend="mvc-exceptionhandlers"/> |
instead.</para> |
||||||
including information on customizing the default Servlet container error page.</para> |
|
||||||
|
<para>See the revised <xref linkend="mvc-exceptionhandlers" /> including |
||||||
</section> |
information on customizing the default Servlet container error |
||||||
|
page.</para> |
||||||
<section xml:id="new-in-3.2-webmvc-generic-types-rest-template"> |
</section> |
||||||
<title>Support for generic types in the <classname>RestTemplate</classname> and in |
|
||||||
<interfacename>@RequestBody</interfacename> arguments</title> |
<section xml:id="new-in-3.2-webmvc-generic-types-rest-template"> |
||||||
|
<title>Support for generic types in the |
||||||
<para>The <classname>RestTemplate</classname> can now read an HTTP |
<classname>RestTemplate</classname> and in |
||||||
response to a generic type (e.g. <code>List<Account></code>). |
<interfacename>@RequestBody</interfacename> arguments</title> |
||||||
There are three new <code>exchange()</code> methods that accept |
|
||||||
<classname>ParameterizedTypeReference</classname>, a |
<para>The <classname>RestTemplate</classname> can now read an HTTP |
||||||
new class that enables capturing and passing generic type info.</para> |
response to a generic type (e.g. <code>List<Account></code>). There |
||||||
|
are three new <code>exchange()</code> methods that accept |
||||||
<para>In support of this feature, the <interfacename>HttpMessageConverter</interfacename> |
<classname>ParameterizedTypeReference</classname>, a new class that |
||||||
is extended by <interfacename>GenericHttpMessageConverter</interfacename> |
enables capturing and passing generic type info.</para> |
||||||
adding a method for reading content given a specified parameterized type. |
|
||||||
The new interface is implemented by the |
<para>In support of this feature, the |
||||||
<classname>MappingJacksonHttpMessageConverter</classname> and also |
<interfacename>HttpMessageConverter</interfacename> is extended by |
||||||
by a new <classname>Jaxb2CollectionHttpMessageConverter</classname> that can |
<interfacename>GenericHttpMessageConverter</interfacename> adding a method |
||||||
read read a generic <interfacename>Collection</interfacename> where the |
for reading content given a specified parameterized type. The new |
||||||
generic type is a JAXB type annotated with |
interface is implemented by the |
||||||
<interfacename>@XmlRootElement</interfacename> or |
<classname>MappingJacksonHttpMessageConverter</classname> and also by a |
||||||
<interfacename>@XmlType</interfacename>.</para> |
new <classname>Jaxb2CollectionHttpMessageConverter</classname> that can |
||||||
|
read read a generic <interfacename>Collection</interfacename> where the |
||||||
</section> |
generic type is a JAXB type annotated with |
||||||
|
<interfacename>@XmlRootElement</interfacename> or |
||||||
<section xml:id="new-in-3.2-webmvc-jackson-json"> |
<interfacename>@XmlType</interfacename>.</para> |
||||||
<title>Jackson JSON 2 and related improvements</title> |
</section> |
||||||
|
|
||||||
<para>The Jackson Json 2 library is now supported. Due to packaging changes in |
<section xml:id="new-in-3.2-webmvc-jackson-json"> |
||||||
the Jackson library, there are separate classes in Spring MVC as well. Those are |
<title>Jackson JSON 2 and related improvements</title> |
||||||
<classname>MappingJackson2HttpMessageConverter</classname> and |
|
||||||
<classname>MappingJackson2JsonView</classname>. |
<para>The Jackson JSON 2 library is now supported. Due to packaging |
||||||
Other related configuration improvements include support for |
changes in the Jackson library, there are separate classes in Spring MVC |
||||||
pretty printing as well as a |
as well. Those are |
||||||
<classname>JacksonObjectMapperFactoryBean</classname> for convenient |
<classname>MappingJackson2HttpMessageConverter</classname> and |
||||||
customization of an <classname>ObjectMapper</classname> in |
<classname>MappingJackson2JsonView</classname>. Other related |
||||||
XML configuration.</para> |
configuration improvements include support for pretty printing as well as |
||||||
|
a <classname>JacksonObjectMapperFactoryBean</classname> for convenient |
||||||
</section> |
customization of an <classname>ObjectMapper</classname> in XML |
||||||
|
configuration.</para> |
||||||
<section xml:id="new-in-3.2-webmvc-request-body-arg-with-binding-result"> |
</section> |
||||||
<title><interfacename>@RequestBody</interfacename> improvements</title> |
|
||||||
|
<section xml:id="new-in-3.2-webmvc-request-body-arg-with-binding-result"> |
||||||
<para>An <interfacename>@RequestBody</interfacename> or an |
<title><interfacename>@RequestBody</interfacename> improvements</title> |
||||||
<interfacename>@RequestPart</interfacename> argument can now be followed by an |
|
||||||
<interfacename>Errors</interfacename> argument making it possible to handle |
<para>An <interfacename>@RequestBody</interfacename> or an |
||||||
validation errors (as a result of an <interfacename>@Valid</interfacename> |
<interfacename>@RequestPart</interfacename> argument can now be followed |
||||||
annotation) locally within the <interfacename>@RequestMapping</interfacename> method. |
by an <interfacename>Errors</interfacename> argument making it possible to |
||||||
<interfacename>@RequestBody</interfacename> now also supports |
handle validation errors (as a result of an |
||||||
a required flag.</para> |
<interfacename>@Valid</interfacename> annotation) locally within the |
||||||
|
<interfacename>@RequestMapping</interfacename> method. |
||||||
</section> |
<interfacename>@RequestBody</interfacename> now also supports a required |
||||||
|
flag.</para> |
||||||
<section xml:id="new-in-3.2-webmvc-http-patch"> |
</section> |
||||||
<title>HTTP PATCH method</title> |
|
||||||
|
<section xml:id="new-in-3.2-webmvc-http-patch"> |
||||||
<para>The HTTP request method <code>PATCH</code> may now be used in |
<title>HTTP PATCH method</title> |
||||||
<interfacename>@RequestMapping</interfacename> methods as well as in |
|
||||||
the <classname>RestTemplate</classname> in conjunction with |
<para>The HTTP request method <code>PATCH</code> may now be used in |
||||||
Apache HttpComponents HttpClient version 4.2 or later. |
<interfacename>@RequestMapping</interfacename> methods as well as in the |
||||||
The JDK <classname>HttpURLConnection</classname> does not support the |
<classname>RestTemplate</classname> in conjunction with Apache |
||||||
<code>PATCH</code> method.</para> |
HttpComponents HttpClient version 4.2 or later. The JDK |
||||||
|
<classname>HttpURLConnection</classname> does not support the |
||||||
</section> |
<code>PATCH</code> method.</para> |
||||||
|
</section> |
||||||
<section xml:id="new-in-3.2-webmvc-mapped-interceptor-exclude-patterns"> |
|
||||||
<title>Excluded patterns in mapped interceptors</title> |
<section xml:id="new-in-3.2-webmvc-mapped-interceptor-exclude-patterns"> |
||||||
|
<title>Excluded patterns in mapped interceptors</title> |
||||||
<para>Mapped interceptors now support URL patterns to be excluded. |
|
||||||
The MVC namespace and the MVC Java config both expose these options.</para> |
<para>Mapped interceptors now support URL patterns to be excluded. The MVC |
||||||
|
namespace and the MVC JavaConfig both expose these options.</para> |
||||||
</section> |
</section> |
||||||
|
|
||||||
<section xml:id="new-in-3.2-date-time-format-without-joda"> |
<section xml:id="new-in-3.2-date-time-format-without-joda"> |
||||||
<title>Support for <interfacename>@DateTimeFormat</interfacename> without Joda Time</title> |
<title>Support for <interfacename>@DateTimeFormat</interfacename> without |
||||||
<para>The <interfacename>@DateTimeFormat</interfacename> annotation can now be |
Joda Time</title> |
||||||
used without needing a dependency on the Joda Time library. If Joda Time is not |
|
||||||
present the JDK <classname>SimpleDateFormat</classname> will be used to parse and |
<para>The <interfacename>@DateTimeFormat</interfacename> annotation can |
||||||
print date patterns. When Joda time is present it will continue to be used in |
now be used without needing a dependency on the Joda Time library. If Joda |
||||||
preference to <classname>SimpleDateFormat</classname>. |
Time is not present the JDK <classname>SimpleDateFormat</classname> will |
||||||
</para> |
be used to parse and print date patterns. When Joda Time is present it |
||||||
</section> |
will continue to be used in preference to |
||||||
|
<classname>SimpleDateFormat</classname>.</para> |
||||||
<section xml:id="new-in-3.2-global-date-time-format"> |
</section> |
||||||
<title>Global date & time formatting</title> |
|
||||||
<para>It is now possible to define global formats that will be used when parsing |
<section xml:id="new-in-3.2-global-date-time-format"> |
||||||
and printing date and time types. See |
<title>Global date & time formatting</title> |
||||||
<xref linkend="format-configuring-formatting-globaldatetimeformat"/> for details. |
|
||||||
</para> |
<para>It is now possible to define global formats that will be used when |
||||||
</section> |
parsing and printing date and time types. See <xref |
||||||
|
linkend="format-configuring-formatting-globaldatetimeformat" /> for |
||||||
|
details.</para> |
||||||
|
</section> |
||||||
|
|
||||||
|
<section xml:id="new-in-3.2-testing"> |
||||||
|
<title>New Testing Features</title> |
||||||
|
|
||||||
|
<para>In addition to the aforementioned inclusion of the <link |
||||||
|
linkend="spring-mvc-test-framework">Spring MVC Test Framework</link> in |
||||||
|
the <literal>spring-test</literal> module, the <emphasis>Spring |
||||||
|
TestContext Framework</emphasis> has been revised with support for |
||||||
|
integration testing web applications as well as configuring application |
||||||
|
contexts with context initializers. For further details, consult the |
||||||
|
following.</para> |
||||||
|
|
||||||
|
<itemizedlist> |
||||||
|
<listitem> |
||||||
|
<para>Configuring and <link |
||||||
|
linkend="testcontext-ctx-management-web">loading a |
||||||
|
WebApplicationContext</link> in integration tests</para> |
||||||
|
</listitem> |
||||||
|
|
||||||
|
<listitem> |
||||||
|
<para>Testing <link linkend="testcontext-web-scoped-beans">request and |
||||||
|
session scoped beans</link></para> |
||||||
|
</listitem> |
||||||
|
|
||||||
|
<listitem> |
||||||
|
<para>Improvements to <link linkend="mock-objects-servlet">Servlet API |
||||||
|
mocks</link></para> |
||||||
|
</listitem> |
||||||
|
|
||||||
|
<listitem> |
||||||
|
<para>Configuring test application contexts with <link |
||||||
|
linkend="testcontext-ctx-management-initializers">ApplicationContextInitializers</link></para> |
||||||
|
</listitem> |
||||||
|
</itemizedlist> |
||||||
</section> |
</section> |
||||||
</chapter> |
</chapter> |
||||||
|
|||||||
Loading…
Reference in new issue