spring3使用@ResponseBody 输出乱码,加入此配置
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<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>
</list>
</property>
</bean>
我经过测试,发现用了<mvc:annotation-driven />这个后,就算用了spring字符过滤器,也会有乱码,于是我去掉了<mvc:a
nnotation-driven />配置改用楼主的配置方法,确实能解决乱码问题
但发现,若web.xml里配置了org.springframework.web.context.ContextLoaderListener那么通过DispatcherServlet的路径映射,全都无法访问,但若是在xxx-servlet.xml采用这段<mvc:annotation-driven />配置,又正常访问,就是又有乱码问题
纠结呀
问题已经解决,项目都在线上跑了。
把楼主的配置写在<mvc:annotation-driven />之前就没问题了。