相关的代码在org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser.parse 方法中实现的,分别注册RequestMappingHandlerMapping,RequestMappingHandlerAdapter,ExceptionHandlerExceptionResolver,ResponseStatusExceptionResolver,DefaultHandlerExceptionResolver 到spring 容器,对于RequestMappingHandlerAdapter和ExceptionHandlerExceptionResolver一个重要的属性是messageConverters 用来进行消息转换。如果jackson和jaxb 库在classpath下,那么就会注册Jaxb2RootElementHttpMessageConverter和MappingJackson2HttpMessageConverter,当一个RequestMapping方法添加了@ResponseBody注解后,就会相应地转为json或者xml字符串
Posted in: spring practise
Comments are closed.