使用spring mvc时,我们会在配置文件里添加<mvc:annotation-driven /><beans>
这个配置文件都加载了那些类呢?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类似controller中ajax请求直接返回对象被组装成json格式,就是由于该配置文件注册了MappingJacksonHttpMessageConverter对象,当我们的工程引入了jackson相关的jar包,spring就可以自动将我们的返回对象封装成json对象输出给客户端。. * 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 withXmlRootElement, 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.