zoukankan      html  css  js  c++  java
  • pringMVC 配置StringHttpMessageConverter不生效问题

    当使用@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是不生效的!
  • 相关阅读:
    RabbitMqBase消息队列小结
    PtrSwap不仅仅是原地交换两个数
    InterfaceSummary接口小结
    InterfaceDesign接口设计原则
    InitOrder初始化执行顺序
    golang面向对象编程思想
    golang之工厂模式
    golang之方法
    golang之结构体使用注意事项和细节
    golang之匿名函数结合defer
  • 原文地址:https://www.cnblogs.com/shown/p/6518669.html
Copyright © 2011-2022 走看看