首页 > Web开发 > 详细

pringMVC 配置StringHttpMessageConverter不生效问题

时间:2017-03-08 12:52:26      阅读:313      评论:0      收藏:0      [点我收藏+]
当使用@ResponseBody返回的字符串带有中文时,返回类型为String会被StringHttpMessageConverter处理,当时查看源码发现默认的Charset DEFAULT_CHARSET使用的是ISO-8859-1。
context.xml里有配置如下信息时候,但是发现没有生效。需要把这段配置在<mvc:annotation-driven/>注解前面!
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper" value="#{jsonUtil.objectMapper}"/>
<property name="supportedMediaTypes">
<list>
<value>text/json;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>

</bean>
<mvc:annotation-driven/> //这行配置在后面上面的配置才会生效,spring启动的时候这行注解做的事情会初始化各种配置,包括上面的配置所做的事情,后面再注入到spring是不生效的!

pringMVC 配置StringHttpMessageConverter不生效问题

原文:http://www.cnblogs.com/shown/p/6518669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!