|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<chapter xmlns="http://docbook.org/ns/docbook" version="5.0" |
| 3 | + xmlns:xlink="http://www.w3.org/1999/xlink" |
| 4 | + xmlns:xi="http://www.w3.org/2001/XInclude" |
| 5 | + xml:id="new-in-3.2"> |
| 6 | + <title>New Features and Enhancements in Spring 3.2</title> |
| 7 | + |
| 8 | + <section id="new-in-3.2-features-overview"> |
| 9 | + <title>Overview of new features</title> |
| 10 | + |
| 11 | + <section id="new-in-3.2-webmvc-async"> |
| 12 | + <title>Support for Servlet 3 based asynchronous request processing</title> |
| 13 | + |
| 14 | + <para>The Spring MVC programming model now provides explicit Servlet 3 async support. |
| 15 | + <interfacename>@RequestMapping</interfacename> methods can return one of:</para> |
| 16 | + |
| 17 | + <itemizedlist> |
| 18 | + <listitem> |
| 19 | + <para><interfacename>java.util.concurrent.Callable</interfacename> to |
| 20 | + complete processing in a separate thread managed by a task executor |
| 21 | + within Spring MVC.</para> |
| 22 | + </listitem> |
| 23 | + <listitem> |
| 24 | + <para><classname>org.springframework.web.context.request.async.DeferredResult</classname> |
| 25 | + to complete processing at a later time from a thread not known to |
| 26 | + Spring MVC, e.g. in response to some external event (JSM, AMQP, etc.)</para> |
| 27 | + </listitem> |
| 28 | + <listitem> |
| 29 | + <para><classname>org.springframework.web.context.request.async.AsyncTask</classname> |
| 30 | + to wrap a <interfacename>Callable</interfacename> and |
| 31 | + customize the timeout value or the task executor to use.</para> |
| 32 | + </listitem> |
| 33 | + </itemizedlist> |
| 34 | + |
| 35 | + <para>See <ulink |
| 36 | + url="http://blog.springsource.org/2012/05/06/spring-mvc-3-2-preview-introducing-servlet-3-async-support/"> |
| 37 | + Introducing Servlet 3 Async Support</ulink> (SpringSource team blog).</para> |
| 38 | + |
| 39 | + </section> |
| 40 | + |
| 41 | + <section id="new-in-3.2-webmvc-content-negotiation"> |
| 42 | + <title>Content negotiation improvements</title> |
| 43 | + |
| 44 | + <para>A <interfacename>ContentNeogtiationStrategy</interfacename> is now |
| 45 | + available for resolving the requested media types from an incoming request. |
| 46 | + The available implementations are based on path extension, request parameter, |
| 47 | + 'Accept' header, and a fixed default content type. Equivalent options were |
| 48 | + previously available only in the ContentNegotiatingViewResolver but are now |
| 49 | + available throughout.</para> |
| 50 | + |
| 51 | + <para><classname>ContentNegotiationManager</classname> is the central class to |
| 52 | + use when configuring content negotiation options. It accepts one or |
| 53 | + more ContentNeogtiationStrategy instances and delegates to them. It can be |
| 54 | + plugged into <classname>RequestMappingHandlerMapping</classname>, |
| 55 | + <classname>RequestMappingHandlerAdapter</classname>, |
| 56 | + <classname>ExceptionHandlerExceptionResolver</classname>, |
| 57 | + and <classname>ContentNegotiatingViewResolver</classname>. The MVC |
| 58 | + namespace and the MVC Java config provide convenient options to configure |
| 59 | + all that.</para> |
| 60 | + |
| 61 | + <para>The introduction of <classname>ContentNegotiationManger</classname> |
| 62 | + also enables smart suffix pattern matching for incoming requests. |
| 63 | + See <ulink url="https://github.com/SpringSource/spring-framework/commit/4fd7645"> |
| 64 | + commit message</ulink></para> |
| 65 | + |
| 66 | + </section> |
| 67 | + |
| 68 | + <section id="new-in-3.2-webmvc-controller-advice"> |
| 69 | + <title><interfacename>@ControllerAdvice</interfacename> annotation</title> |
| 70 | + |
| 71 | + <para>Classes annotated with <interfacename>@ControllerAdvice</interfacename> |
| 72 | + can contain <interfacename>@ExceptionHandler</interfacename>, |
| 73 | + <interfacename>@InitBinder</interfacename>, and |
| 74 | + <interfacename>@ModelAttribute</interfacename> methods and those will apply |
| 75 | + to <interfacename>@RequestMapping</interfacename> methods across controller |
| 76 | + hierarchies as opposed to the controller hierarchy within which they are declared. |
| 77 | + <interfacename>@ControllerAdvice</interfacename> is |
| 78 | + a component annotation allowing implementation classes to be auto-detected |
| 79 | + through classpath scanning.</para> |
| 80 | + |
| 81 | + </section> |
| 82 | + |
| 83 | + <section id="new-in-3.2-webmvc-exception-handler-support"> |
| 84 | + <title><classname>ExceptionHandlerSupport</classname> class</title> |
| 85 | + |
| 86 | + <para>A convenient base class with an |
| 87 | + <interfacename>@ExceptionHandler</interfacename> |
| 88 | + method that handles standard Spring MVC exceptions, just as the |
| 89 | + <classname>DefaultHandlerExceptionResolver</classname> does, but also |
| 90 | + allowing you to prepare error content for the body of the response.</para> |
| 91 | + |
| 92 | + </section> |
| 93 | + |
| 94 | + <section id="new-in-3.2-webmvc-generic-types-rest-template"> |
| 95 | + <title>Support for generic types in the <classname>RestTemplate</classname> and in |
| 96 | + <interfacename>@RequestBody</interfacename> arguments</title> |
| 97 | + |
| 98 | + <para>The <classname>RestTemplate</classname> can now read an HTTP |
| 99 | + response to a generic type (e.g. <code>List<Account></code>). |
| 100 | + There are three new <code>exchange()</code> methods that accept |
| 101 | + <classname>ParameterizedTypeReference</classname>, a |
| 102 | + new class that enables capturing and passing generic type info.</para> |
| 103 | + |
| 104 | + <para>In support of this feature, the <interfacename>HttpMessageConverter</interfacename> |
| 105 | + is extended by <interfacename>GenericHttpMessageConverter</interfacename> |
| 106 | + adding a method for reading content given a specified parameterized type. |
| 107 | + The new interface is implemented by the |
| 108 | + <classname>MappingJacksonHttpMessageConverter</classname> and also |
| 109 | + by a new <classname>Jaxb2CollectionHttpMessageConverter</classname> that can |
| 110 | + read read a generic <interfacename>Collection</interfacename> where the |
| 111 | + generic type is a JAXB type annotated with |
| 112 | + <interfacename>@XmlRootElement</interfacename> or |
| 113 | + <interfacename>@XmlType</interfacename>.</para> |
| 114 | + |
| 115 | + </section> |
| 116 | + |
| 117 | + <section id="new-in-3.2-webmvc-jackson-json"> |
| 118 | + <title>Jackson JSON 2 and related improvements</title> |
| 119 | + |
| 120 | + <para>The Jackson Json 2 library is now supported. Due to packaging changes in |
| 121 | + the Jackson library, there are separate classes in Spring MVC as well. Those are |
| 122 | + <classname>MappingJackson2HttpMessageConverter</classname> and |
| 123 | + <classname>MappingJackson2JsonView</classname>. |
| 124 | + Other related configuration improvements include support for |
| 125 | + pretty printing as well as a |
| 126 | + <classname>JacksonObjectMapperFactoryBean</classname> for convenient |
| 127 | + customization of an <classname>ObjectMapper</classname> in |
| 128 | + XML configuration.</para> |
| 129 | + |
| 130 | + </section> |
| 131 | + |
| 132 | + <section id="new-in-3.2-webmvc-request-body-arg-with-binding-result"> |
| 133 | + <title><interfacename>@RequestBody</interfacename> improvements</title> |
| 134 | + |
| 135 | + <para>An <interfacename>@RequestBody</interfacename> or an |
| 136 | + <interfacename>@RequestPart</interfacename> argument can now be followed by an |
| 137 | + <interfacename>Errors</interfacename> argument making it possible to handle |
| 138 | + validation errors (as a result of an <interfacename>@Valid</interfacename> |
| 139 | + annotation) locally within the <interfacename>@RequestMapping</interfacename> method. |
| 140 | + <interfacename>@RequestBody</interfacename> now also supports |
| 141 | + a required flag.</para> |
| 142 | + |
| 143 | + </section> |
| 144 | + |
| 145 | + <section id="new-in-3.2-webmvc-http-patch"> |
| 146 | + <title>HTTP PATCH method</title> |
| 147 | + |
| 148 | + <para>The HTTP request method <code>PATCH</code> may now be used in |
| 149 | + <interfacename>@RequestMapping</interfacename> methods as well as in |
| 150 | + the <classname>RestTemplate</classname> in conjunction with |
| 151 | + Apache HttpComponents HttpClient version 4.2 or later. |
| 152 | + The JDK <classname>HttpURLConnection</classname> does not support the |
| 153 | + <code>PATCH</code> method.</para> |
| 154 | + |
| 155 | + </section> |
| 156 | + |
| 157 | + <section id="new-in-3.2-webmvc-mapped-interceptor-exclude-patterns"> |
| 158 | + <title>Excluded patterns in mapped interceptors</title> |
| 159 | + |
| 160 | + <para>Mapped interceptors now support URL patterns to be excluded. |
| 161 | + The MVC namespace and the MVC Java config both expose these options.</para> |
| 162 | + |
| 163 | + </section> |
| 164 | + |
| 165 | + </section> |
| 166 | +</chapter> |
0 commit comments