diff --git a/src/reference/docbook/new-in-3.2.xml b/src/reference/docbook/new-in-3.2.xml index 19a1f9dc9d0..7f971419aec 100644 --- a/src/reference/docbook/new-in-3.2.xml +++ b/src/reference/docbook/new-in-3.2.xml @@ -1,225 +1,262 @@ - + New Features and Enhancements in Spring 3.2 -
- Overview of new features - -
- Support for Servlet 3 based asynchronous request processing - - The Spring MVC programming model now provides explicit Servlet 3 async support. - @RequestMapping methods can return one of: - - - - java.util.concurrent.Callable to - complete processing in a separate thread managed by a task executor - within Spring MVC. - - - org.springframework.web.context.request.async.DeferredResult - 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.) - - - org.springframework.web.context.request.async.AsyncTask - to wrap a Callable and - customize the timeout value or the task executor to use. - - - - See - Introducing Servlet 3 Async Support (SpringSource team blog). - -
- -
- Spring MVC Test framework - - First-class support for testing Spring MVC applications with a - fluent API and without a servlet container. Server-side tests involve - use of the DispatcherServlet while client-side - REST tests rely on the RestTemplate. - See . - - -
- -
- Content negotiation improvements - - A ContentNeogtiationStrategy 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. - - ContentNegotiationManager 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 RequestMappingHandlerMapping, - RequestMappingHandlerAdapter, - ExceptionHandlerExceptionResolver, - and ContentNegotiatingViewResolver. The MVC - namespace and the MVC Java config provide convenient options to configure - all that. - - The introduction of ContentNegotiationManger - also enables smart suffix pattern matching for incoming requests. - See - commit message - -
- -
- <interfacename>@ControllerAdvice</interfacename> annotation - - Classes annotated with @ControllerAdvice - can contain @ExceptionHandler, - @InitBinder, and - @ModelAttribute methods and those will apply - to @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. - -
- -
- Matrix variables - - A new @MatrixVariable annotation - adds support for extracting matrix variables from the request URI. - For more details see . -
- -
- Abstract base class for code-based Servlet 3+ container initialization - - 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 - sub-class AbstractAnnotationConfigDispatcherServletInitializer - can be used with Java-based Spring configuration. - For more details see . -
- -
- <classname>ResponseEntityExceptionHandler</classname> class - - 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 DefaultHandlerExceptionResolver, which does - the same but returns a ModelAndView instead. - - See the revised - including information on customizing the default Servlet container error page. - -
- -
- Support for generic types in the <classname>RestTemplate</classname> and in - <interfacename>@RequestBody</interfacename> arguments - - The RestTemplate can now read an HTTP - response to a generic type (e.g. List<Account>). - There 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 new Jaxb2CollectionHttpMessageConverter that can - read read a generic Collection where the - generic type is a JAXB type annotated with - @XmlRootElement or - @XmlType. - -
- -
- Jackson JSON 2 and related improvements - - 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 - MappingJackson2HttpMessageConverter and - MappingJackson2JsonView. - Other related configuration improvements include support for - pretty printing as well as a - JacksonObjectMapperFactoryBean for convenient - customization of an ObjectMapper in - XML configuration. - -
- -
- <interfacename>@RequestBody</interfacename> improvements - - An @RequestBody or an - @RequestPart argument can now be followed by an - Errors argument making it possible to handle - validation errors (as a result of an @Valid - annotation) locally within the @RequestMapping method. - @RequestBody now also supports - a required flag. - -
- -
- HTTP PATCH method - - 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 - PATCH method. - -
- -
- Excluded patterns in mapped interceptors - - Mapped interceptors now support URL patterns to be excluded. - The MVC namespace and the MVC Java config both expose these options. - -
- -
- Support for <interfacename>@DateTimeFormat</interfacename> without Joda Time - The @DateTimeFormat annotation can now be - used without needing a dependency on the Joda Time library. If Joda Time is not - present the JDK SimpleDateFormat will be used to parse and - print date patterns. When Joda time is present it will continue to be used in - preference to SimpleDateFormat. - -
- -
- Global date & time formatting - It is now possible to define global formats that will be used when parsing - and printing date and time types. See - for details. - -
+
+ Support for Servlet 3 based asynchronous request processing + + The Spring MVC programming model now provides explicit Servlet 3 + async support. @RequestMapping methods can + return one of: + + + + java.util.concurrent.Callable to + complete processing in a separate thread managed by a task executor + within Spring MVC. + + + + org.springframework.web.context.request.async.DeferredResult + to complete processing at a later time from a thread not known to + Spring MVC — for example, in response to some external event (JMS, + AMQP, etc.) + + + + org.springframework.web.context.request.async.AsyncTask + to wrap a Callable and customize the + timeout value or the task executor to use. + + + + See + Introducing Servlet 3 Async Support (SpringSource team + blog). +
+ +
+ Spring MVC Test framework + + First-class support for testing Spring MVC applications with a + fluent API and without a Servlet container. Server-side tests involve use + of the DispatcherServlet while client-side REST + tests rely on the RestTemplate. See . +
+ +
+ Content negotiation improvements + + A ContentNeogtiationStrategy 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. + + ContentNegotiationManager 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 RequestMappingHandlerMapping, + RequestMappingHandlerAdapter, + ExceptionHandlerExceptionResolver, and + ContentNegotiatingViewResolver. The MVC namespace + and the MVC JavaConfig provide convenient options to configure all + that. + + The introduction of ContentNegotiationManger + also enables smart suffix pattern matching for incoming requests. See + commit + message. +
+ +
+ <interfacename>@ControllerAdvice</interfacename> annotation + + Classes annotated with + @ControllerAdvice can contain + @ExceptionHandler, + @InitBinder, and + @ModelAttribute methods and those will + apply to @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. +
+ +
+ Matrix variables + + A new @MatrixVariable annotation adds + support for extracting matrix variables from the request URI. For more + details see . +
+ +
+ Abstract base class for code-based Servlet 3+ container + initialization + + 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 + sub-class + AbstractAnnotationConfigDispatcherServletInitializer + can be used with Java-based Spring configuration. For more details see + . +
+ +
+ <classname>ResponseEntityExceptionHandler</classname> class + + 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 DefaultHandlerExceptionResolver, + which does the same but returns a ModelAndView + instead. + + See the revised including + information on customizing the default Servlet container error + page. +
+ +
+ Support for generic types in the + <classname>RestTemplate</classname> and in + <interfacename>@RequestBody</interfacename> arguments + + The RestTemplate can now read an HTTP + response to a generic type (e.g. List<Account>). There + 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 + new Jaxb2CollectionHttpMessageConverter that can + read read a generic Collection where the + generic type is a JAXB type annotated with + @XmlRootElement or + @XmlType. +
+ +
+ Jackson JSON 2 and related improvements + + 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 + MappingJackson2HttpMessageConverter and + MappingJackson2JsonView. Other related + configuration improvements include support for pretty printing as well as + a JacksonObjectMapperFactoryBean for convenient + customization of an ObjectMapper in XML + configuration. +
+ +
+ <interfacename>@RequestBody</interfacename> improvements + + An @RequestBody or an + @RequestPart argument can now be followed + by an Errors argument making it possible to + handle validation errors (as a result of an + @Valid annotation) locally within the + @RequestMapping method. + @RequestBody now also supports a required + flag. +
+ +
+ HTTP PATCH method + + 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 + PATCH method. +
+ +
+ Excluded patterns in mapped interceptors + + Mapped interceptors now support URL patterns to be excluded. The MVC + namespace and the MVC JavaConfig both expose these options. +
+ +
+ Support for <interfacename>@DateTimeFormat</interfacename> without + Joda Time + + The @DateTimeFormat annotation can + now be used without needing a dependency on the Joda Time library. If Joda + Time is not present the JDK SimpleDateFormat will + be used to parse and print date patterns. When Joda Time is present it + will continue to be used in preference to + SimpleDateFormat. +
+ +
+ Global date & time formatting + + It is now possible to define global formats that will be used when + parsing and printing date and time types. See for + details. +
+ +
+ New Testing Features + + In addition to the aforementioned inclusion of the Spring MVC Test Framework in + the 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 + following. + + + + Configuring and loading a + WebApplicationContext in integration tests + + + + Testing request and + session scoped beans + + + + Improvements to Servlet API + mocks + + + + Configuring test application contexts with ApplicationContextInitializers + +