您的位置:首页 > 编程语言 > Java开发

SpringMVC 3.2.* json 406

2016-06-23 13:34 441 查看
今天项目请求json时报了这个诡异的且从来没有遇到到的错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

解决办法:

1、将springmvc 文件的 xsd修改为3.2版本,如:
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
2、将<mvc:annotation-driven/> 修改为

<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>

这样问题得到解决了。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  springmvc json 406