new-in-3.2.xml 10.9 KB
Newer Older
1
<?xml version="1.0" encoding="UTF-8"?>
2 3 4
<chapter xml:id="new-in-3.2"
    xmlns="http://docbook.org/ns/docbook" version="5.0"
    xmlns:xl="http://www.w3.org/1999/xlink"
5
    xmlns:xi="http://www.w3.org/2001/XInclude"
6 7 8 9
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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">
10 11
  <title>New Features and Enhancements in Spring 3.2</title>

12
  <section xml:id="new-in-3.2-features-overview">
13 14
    <title>Overview of new features</title>

15
    <section xml:id="new-in-3.2-webmvc-async">
16 17 18 19
      <title>Support for Servlet 3 based asynchronous request processing</title>

      <para>The Spring MVC programming model now provides explicit Servlet 3 async support.
      <interfacename>@RequestMapping</interfacename> methods can return one of:</para>
20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
      <itemizedlist>
        <listitem>
          <para><interfacename>java.util.concurrent.Callable</interfacename> to
          complete processing in a separate thread managed by a task executor
          within Spring MVC.</para>
        </listitem>
        <listitem>
          <para><classname>org.springframework.web.context.request.async.DeferredResult</classname>
          to complete processing at a later time from a thread not known to
          Spring MVC, e.g. in response to some external event (JSM, AMQP, etc.)</para>
        </listitem>
        <listitem>
          <para><classname>org.springframework.web.context.request.async.AsyncTask</classname>
          to wrap a <interfacename>Callable</interfacename> and
          customize the timeout value or the task executor to use.</para>
        </listitem>
      </itemizedlist>
38 39 40 41 42

      <para>See <link
          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 blog).</para>

43 44
    </section>

45
    <section xml:id="new-in-3.2-spring-mvc-test">
46 47 48 49 50 51
      <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
      use of the <classname>DispatcherServlet</classname> while client-side
      REST tests rely on the <classname>RestTemplate</classname>.
52
      See <xref linkend="spring-mvc-test-framework"/>.
53 54 55 56
      </para>

    </section>

57
    <section xml:id="new-in-3.2-webmvc-content-negotiation">
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
      <title>Content negotiation improvements</title>

      <para>A <interfacename>ContentNeogtiationStrategy</interfacename> is now
      available for resolving the requested media types from an incoming request.
      The available implementations are based on path extension, request parameter,
      'Accept' header, and a fixed default content type. Equivalent options were
      previously available only in the ContentNegotiatingViewResolver but are now
      available throughout.</para>

      <para><classname>ContentNegotiationManager</classname> is the central class to
      use when configuring content negotiation options. It accepts one or
      more ContentNeogtiationStrategy instances and delegates to them. It can be
      plugged into <classname>RequestMappingHandlerMapping</classname>,
      <classname>RequestMappingHandlerAdapter</classname>,
      <classname>ExceptionHandlerExceptionResolver</classname>,
      and <classname>ContentNegotiatingViewResolver</classname>. The MVC
      namespace and the MVC Java config provide convenient options to configure
      all that.</para>

      <para>The introduction of <classname>ContentNegotiationManger</classname>
      also enables smart suffix pattern matching for incoming requests.
79 80
      See <link xl:href="https://github.com/SpringSource/spring-framework/commit/4fd7645">
      commit message</link></para>
81 82 83

    </section>

84
    <section xml:id="new-in-3.2-webmvc-controller-advice">
85
      <title><interfacename>@ControllerAdvice</interfacename> annotation</title>
86

87 88 89 90 91 92 93 94 95
      <para>Classes annotated with <interfacename>@ControllerAdvice</interfacename>
      can contain <interfacename>@ExceptionHandler</interfacename>,
      <interfacename>@InitBinder</interfacename>, and
      <interfacename>@ModelAttribute</interfacename> methods and those will apply
      to <interfacename>@RequestMapping</interfacename> methods across controller
      hierarchies as opposed to the controller hierarchy within which they are declared.
      <interfacename>@ControllerAdvice</interfacename> is
      a component annotation allowing implementation classes to be auto-detected
      through classpath scanning.</para>
96

97 98
    </section>

99
    <section xml:id="new-in-3.2-matrix-variables">
100 101 102 103 104 105 106
      <title>Matrix variables</title>

      <para>A new <interfacename>@MatrixVariable</interfacename> annotation
      adds support for extracting matrix variables from the request URI.
      For more details see <xref linkend="mvc-ann-matrix-variables"/>.</para>
    </section>

107
    <section xml:id="new-in-3.2-dispatcher-servlet-initializer">
108 109 110 111 112 113 114 115 116 117 118 119
      <title>Abstract base class for code-based Servlet 3+ container initialization</title>

      <para>An abstract base class implementation of the
      <interfacename>WebApplicationInitializer</interfacename> interface is provided to
      simplify code-based registration of a DispatcherServlet and filters
      mapped to it. The new class is named
      <classname>AbstractDispatcherServletInitializer</classname> and its
      sub-class <classname>AbstractAnnotationConfigDispatcherServletInitializer</classname>
      can be used with Java-based Spring configuration.
      For more details see <xref linkend="mvc-container-config"/>.</para>
    </section>

120
    <section xml:id="new-in-3.2-webmvc-exception-handler-support">
121
      <title><classname>ResponseEntityExceptionHandler</classname> class</title>
122 123 124

      <para>A convenient base class with an
      <interfacename>@ExceptionHandler</interfacename>
125 126 127 128 129 130 131 132
      method that handles standard Spring MVC exceptions and returns a
      <classname>ResponseEntity</classname> that allowing customizing and writing
      the response with HTTP message converters. This servers as an alternative
      to the <classname>DefaultHandlerExceptionResolver</classname>, which does
      the same but returns a <classname>ModelAndView</classname> instead.</para>

      <para>See the revised <xref linkend="mvc-exceptionhandlers"/>
      including information on customizing the default Servlet container error page.</para>
133 134 135

    </section>

136
    <section xml:id="new-in-3.2-webmvc-generic-types-rest-template">
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
      <title>Support for generic types in the <classname>RestTemplate</classname> and in
        <interfacename>@RequestBody</interfacename> arguments</title>

      <para>The <classname>RestTemplate</classname> can now read an HTTP
      response to a generic type (e.g. <code>List&lt;Account&gt;</code>).
      There are three new <code>exchange()</code> methods that accept
      <classname>ParameterizedTypeReference</classname>, a
      new class that enables capturing and passing generic type info.</para>

      <para>In support of this feature, the <interfacename>HttpMessageConverter</interfacename>
      is extended by <interfacename>GenericHttpMessageConverter</interfacename>
      adding a method for reading content given a specified parameterized type.
      The new interface is implemented by the
      <classname>MappingJacksonHttpMessageConverter</classname> and also
      by a new <classname>Jaxb2CollectionHttpMessageConverter</classname> that can
      read read a generic <interfacename>Collection</interfacename> where the
      generic type is a JAXB type annotated with
      <interfacename>@XmlRootElement</interfacename> or
      <interfacename>@XmlType</interfacename>.</para>
156

157 158
    </section>

159
    <section xml:id="new-in-3.2-webmvc-jackson-json">
160 161 162 163 164 165 166 167 168 169 170 171 172 173
      <title>Jackson JSON 2 and related improvements</title>

      <para>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
      <classname>MappingJackson2HttpMessageConverter</classname> and
      <classname>MappingJackson2JsonView</classname>.
      Other related configuration improvements include support for
      pretty printing as well as a
      <classname>JacksonObjectMapperFactoryBean</classname> for convenient
      customization of an <classname>ObjectMapper</classname> in
      XML configuration.</para>

    </section>

174
    <section xml:id="new-in-3.2-webmvc-request-body-arg-with-binding-result">
175 176 177 178 179 180 181 182 183 184 185 186
      <title><interfacename>@RequestBody</interfacename> improvements</title>

      <para>An <interfacename>@RequestBody</interfacename> or an
      <interfacename>@RequestPart</interfacename> argument can now be followed by an
      <interfacename>Errors</interfacename> argument making it possible to handle
      validation errors (as a result of an <interfacename>@Valid</interfacename>
      annotation) locally within the <interfacename>@RequestMapping</interfacename> method.
      <interfacename>@RequestBody</interfacename> now also supports
      a required flag.</para>

    </section>

187
    <section xml:id="new-in-3.2-webmvc-http-patch">
188 189 190 191 192 193 194 195 196 197 198
      <title>HTTP PATCH method</title>

      <para>The HTTP request method <code>PATCH</code> may now be used in
      <interfacename>@RequestMapping</interfacename> methods as well as in
      the <classname>RestTemplate</classname> in conjunction with
      Apache HttpComponents HttpClient version 4.2 or later.
      The JDK <classname>HttpURLConnection</classname> does not support the
      <code>PATCH</code> method.</para>

    </section>

199
    <section xml:id="new-in-3.2-webmvc-mapped-interceptor-exclude-patterns">
200 201 202 203 204 205 206
      <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>

    </section>

P
Phillip Webb 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    <section xml:id="new-in-3.2-date-time-format-without-joda">
        <title>Support for <interfacename>@DateTimeFormat</interfacename> without Joda Time</title>
        <para>The <interfacename>@DateTimeFormat</interfacename> annotation can now be
        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
        print date patterns. When Joda time is present it will continue to be used in
        preference to <classname>SimpleDateFormat</classname>.
        </para>
    </section>

    <section xml:id="new-in-3.2-global-date-time-format">
        <title>Global date &amp; time formatting</title>
        <para>It is now possible to define global formats that will be used when parsing
        and printing date and time types.  See
        <xref linkend="format-configuring-formatting-globaldatetimeformat"/> for details.
        </para>
    </section>
224 225
  </section>
</chapter>