SpringMVC 3.2.* json 406

今天項目請求json時報了這個詭異的且歷來沒有遇到到的錯誤:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.web

解決辦法:spring

一、將springmvc 文件的 xsd修改成3.2版本,如:json

http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdspring-mvc

二、將<mvc:annotation-driven/> 修改成mvc

<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/>
    <bean id="contentNegotiationManager"
          class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
        <property name="favorPathExtension" value="false" />
        <property name="favorParameter" value="true" />
        <property name="parameterName" value="mediaType" />
        <property name="ignoreAcceptHeader" value="true"/>
        <property name="useJaf" value="false"/>
        <property name="defaultContentType" value="application/json" />

        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json" />
                <entry key="xml" value="application/xml" />
            </map>
        </property>
    </bean>app

這樣問題獲得解決了。。ide

相關文章
相關標籤/搜索