場景:使用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