Spring mvc:annotation-driven
来源:互联网 发布:淘宝开网店用18 编辑:程序博客网 时间:2024/05/16 18:20
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8"/> </bean> <!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true --> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="prettyPrint" value="true"/> </bean> </mvc:message-converters> </mvc:annotation-driven>
如果在spring-mvc。xml文件中配置了mvc:annotation-driven 那么服务器启动的时候会创建一个
RequestMappingHandlerAdapter对象
RequestResponseBodyMethodProcessor
@Configurationpublic class WebMvcConfiguration extends WebMvcConfigurationSupport {/** * 改变ReturnValueHandlers的顺序<br> * 加入自定义RequestResponseBodyMethodProcessorExt * {@link ServletInvocableHandlerMethod#invokeAndHandle(org.springframework.web.context.request.ServletWebRequest, org.springframework.web.method.support.ModelAndViewContainer, Object...) * * @link HandlerMethodReturnValueHandlerComposite#getReturnValueHandler(MethodParameter)} */@SuppressWarnings("unchecked")public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {RequestMappingHandlerAdapter handlerAdapter = super.requestMappingHandlerAdapter();//List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();StringHttpMessageConverter strConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));//MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();//jacksonConverter.setPrettyPrint(true);messageConverters.add(strConverter);//messageConverters.add(jacksonConverter);// 需要传入参数HttpMessageConverter列表RequestResponseBodyMethodProcessorExt processor = new RequestResponseBodyMethodProcessorExt(messageConverters);try {Method getDefaultReturnValueHandlers = handlerAdapter.getClass().getDeclaredMethod("getDefaultReturnValueHandlers");getDefaultReturnValueHandlers.setAccessible(true);List<HandlerMethodReturnValueHandler> defaultReturnValueHandlers = (List<HandlerMethodReturnValueHandler>) getDefaultReturnValueHandlers.invoke(handlerAdapter);defaultReturnValueHandlers.add(0, processor);handlerAdapter.setReturnValueHandlers(defaultReturnValueHandlers);} catch (Exception e) {e.printStackTrace();}return handlerAdapter;}}如果我在程序中又配置另一个WebMvcConfigurationSupport
会导致创建两个RequestMappingHandlerAdapter对象,从而使WebMvcConfigurationSupport 子类里面的设置无效
0 0
- Spring mvc:annotation-driven
- Spring参考手册 mvc:annotation-driven
- 【Spring MVC】<mvc:annotation-driven/>详解
- Spring MVC 中关于 mvc:annotation-driven
- spring mvc 之mvc:annotation-driven
- Spring MVC之<mvc:annotation-driven/>
- 解析spring MVC3 <mvc:annotation-driven> 实现
- Spring: <mvc:annotation-driven />注解意义
- Spring中<mvc:annotation-driven />的作用
- spring <mvc:annotation-driven />注解意义
- spring mvc的mvc:annotation-driven以及日期的处理
- spring ApplicationContext-mvc之<mvc:annotation-driven />初探
- spring mvc拦截器和<mvc:annotation-driven />的详解
- spring mvc拦截器和<mvc:annotation-driven />的详解
- spring mvc拦截器和<mvc:annotation-driven />的详解
- spring mvc <mvc:annotation-driven>配置使用出现问题
- Spring MVC 解读——<mvc:annotation-driven/>
- Spring MVC 解读——<mvc:annotation-driven/>
- 【前端】-HTML
- 242. Valid Anagram
- hadoop2.x单机搭建分布式集群超详细教程
- 瀑布流无法用<c:forEach>循环遍历
- 分布式多爬虫系统——架构设计
- Spring mvc:annotation-driven
- OSGI企业应用开发(十四)整合Spring、Mybatis、Spring MVC
- C语言------栈的初体验(数组实现)
- 为ubuntu添加有道词典翻译
- cxf Webservice
- 深入理解RunLoop
- 1039. Course List for Student (25)
- JsGrid入门教程及离线文档
- Hibernate一对多级联操作