Spring MVC annotation-driven configuration 

Joined:
01/02/2012
Posts:
9

January 25, 2012 19:27:53    Last update: January 25, 2012 19:28:47
The spring MVC annotation-driven declaration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <mvc:annotation-driven />
<beans>

does the following magic:
  1. Among others, registers:
    • RequestMappingHandlerMapping
    • RequestMappingHandlerAdapter
    • ExceptionHandlerExceptionResolver

    in support of processing requests with annotated controller methods using annotations such as @RequestMapping , @ExceptionHandler, etc.
  2. Enables Spring 3 style type conversion through a ConversionService instance in addition to the JavaBeans PropertyEditors used for Data Binding.
  3. Enables support for formatting Number fields using the @NumberFormat annotation through the ConversionService.
  4. Enables support for formatting Date, Calendar, Long, and Joda Time fields using the @DateTimeFormat annotation, if Joda Time 1.3 or higher is present on the classpath.
  5. Enables support for validating @Controller inputs with @Valid, if a JSR-303 Provider is present on the classpath.
  6. Enables HttpMessageConverter support for @RequestBody method parameters and @ResponseBody method return values from @RequestMapping or @ExceptionHandler methods.

    This is the complete list of HttpMessageConverters set up by mvc:annotation-driven:
    • ByteArrayHttpMessageConverter converts byte arrays.
    • StringHttpMessageConverter converts strings.
    • ResourceHttpMessageConverter converts to/from org.springframework.core.io.Resource for all media types.
    • SourceHttpMessageConverter converts to/from a javax.xml.transform.Source.
    • FormHttpMessageConverter converts form data to/from a MultiValueMap<String, String>.
    • Jaxb2RootElementHttpMessageConverter converts Java objects to/from XML — added if JAXB2 is present on the classpath. This converter can read classes annotated with XmlRootElement and XmlType, and write classes annotated with with XmlRootElement, or subclasses thereof.
    • MappingJacksonHttpMessageConverter converts to/from JSON — added if Jackson is present on the classpath.
    • AtomFeedHttpMessageConverter converts Atom feeds — added if Rome is present on the classpath.
    • RssChannelHttpMessageConverter converts RSS feeds — added if Rome is present on the classpath.

Share |
| Comment  | Tags