Spring MVC annotation-driven configuration
January 25, 2012 19:27:53 Last update: January 25, 2012 19:28:47
The spring MVC
does the following magic:
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:
- Among others, registers:
-
RequestMappingHandlerMapping
-
RequestMappingHandlerAdapter
-
ExceptionHandlerExceptionResolver
in support of processing requests with annotated controller methods using annotations such as@RequestMapping,@ExceptionHandler, etc. -
- Enables Spring 3 style type conversion through a ConversionService instance in addition to the JavaBeans PropertyEditors used for Data Binding.
- Enables support for formatting Number fields using the
@NumberFormatannotation through theConversionService. - Enables support for formatting Date, Calendar, Long, and Joda Time fields using the
@DateTimeFormatannotation, if Joda Time 1.3 or higher is present on the classpath. - Enables support for validating
@Controllerinputs with@Valid, if a JSR-303 Provider is present on the classpath. - Enables
HttpMessageConvertersupport for@RequestBodymethod parameters and@ResponseBodymethod return values from@RequestMappingor@ExceptionHandlermethods.
This is the complete list ofHttpMessageConvertersset up bymvc:annotation-driven:-
ByteArrayHttpMessageConverterconverts byte arrays. -
StringHttpMessageConverterconverts strings. -
ResourceHttpMessageConverterconverts to/fromorg.springframework.core.io.Resourcefor all media types. -
SourceHttpMessageConverterconverts to/from ajavax.xml.transform.Source. -
FormHttpMessageConverterconverts form data to/from aMultiValueMap<String, String>. -
Jaxb2RootElementHttpMessageConverterconverts Java objects to/from XML — added if JAXB2 is present on the classpath. This converter can read classes annotated withXmlRootElementandXmlType, and write classes annotated with withXmlRootElement, or subclasses thereof. -
MappingJacksonHttpMessageConverterconverts to/from JSON — added if Jackson is present on the classpath. -
AtomFeedHttpMessageConverterconverts Atom feeds — added if Rome is present on the classpath. -
RssChannelHttpMessageConverterconverts RSS feeds — added if Rome is present on the classpath.
-