将SpringMVC的jar包升级后,调用ajax时一直都是返回406的响应码,但是后台确实接收到了请求,数据也返回了,但是查看一下返回的数据类型竟然是String,不是object,查找资料后发现SpringMVC4.x版本在配置ajax时有了些改变,配置如下:
<mvc:annotation-driven validator="validator" content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="utf-8"/>
</bean>
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="features">
<array>
<value>WriteMapNullValue</value>
</array>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false"/>
</bean>
4.x版本在配置上需要配置content-negotiation-manager即可解决此问题