美文网首页
Tomcat7 + Spring 3.2.8里的坑:406 Er

Tomcat7 + Spring 3.2.8里的坑:406 Er

作者: hillwind | 来源:发表于2017-06-14 17:24 被阅读0次

今天接手一个SpringMVC的小网站,有一个ajax的json请求总是返回406 Error,经过搜索,发现是3.2.*的版本开始,对于MIME type有了一个协商机制,需要在Spring配置xml里加上如下:

<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="false" />
    <property name="ignoreAcceptHeader" value="false" />
    <property name="mediaTypes" >
        <value>
            atom=application/atom+xml
            html=text/html
            json=application/json
            *=*/*
        </value>
    </property>
</bean>

相关文章

网友评论

      本文标题:Tomcat7 + Spring 3.2.8里的坑:406 Er

      本文链接:https://www.haomeiwen.com/subject/lkheqxtx.html