spring mvc json

问题背景:
    使用了springmvc+velocity的项目,返回json出现了问题

问题描述:
    出现了406错误
    
找不到要解析成的头部!

问题原因:
    缺少json转换配置

解决办法:
    在对应的servlet配置文件中添加
   
xmlns:mvc="http://www.springframework.org/schema/mvc" 

http://www.springframework.org/schema/mvc
           http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

<mvc:annotation-driven>
         <mvc:message-converters register-defaults="false">
            <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                        <value>application/*+json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
     </mvc:annotation-driven>  




原文地址:https://www.cnblogs.com/vvch/p/4871746.html