今天接手一個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>