场景:使用gradle从Spring 4.0.5.RELEASE更新到4.2.2.RELEASE导致端点返回XML而不是JSON 。Spring 4.0.5 - > 4.2.2 XML不再有效 - 端点不再返回JSON
我在我的服务器上有一个端点,它返回一个对象列表。以前,我可以在我的浏览器中打这个端点,并且由于我的JSONView扩展名以好的格式查看JSON对象。然而,在升级Spring之后,同一端点现在在浏览器中显示XML。但是,当使用js向同一端点发出请求时,我会得到JSON。
有什么我需要改变回复到旧的行为,同时仍然保持4.2.2版本?
这似乎是源于这个问题,哪个春天的反应在两个版本之间改变:https://github.com/strongloop/strong-remoting/issues/118。
以下是我的spring-api-servlet.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.XXX.spring" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="jacksonMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jacksonMessageConverter" />
</list>
</property>
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000" />
</bean>
谢谢!加入以下'弹簧API-servlet.xml'工作: '<豆ID = “contentNegotiationManager” 类= “org.springframework.web.accept.ContentNegotiationManagerFactoryBean”> <属性名= “favorPathExtension” 值=“true”/> ' –
将我的评论翻了一个答案,很高兴帮助! – Taylor