2016-08-04 1 views
0

シナリオ:Spring 4.0.5.RELEASEから4.2.2.RELEASEに更新するためにgradleを使用すると、エンドポイントはJSONではなくXMLを返します。Spring 4.0.5 - > 4.2.2 XMLはもはや有効ではありません - JSONを返さないエンドポイント

私はサーバー上にオブジェクトのリストを返すエンドポイントを持っています。以前は、ブラウザでこのエンドポイントに当たって、JSONView拡張機能のためにJSONオブジェクトをすばらしい形式で表示できました。しかし、Springをアップグレードした後、同じエンドポイントでXMLがブラウザに表示されるようになりました。しかし、jsを使用して同じエンドポイントにリクエストを送信すると、JSONが与えられます。

4.2.2リリースを維持したまま古い動作に戻すために変更する必要があるものはありますか?

これは、Springの反応が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> 

+0

ありがとうございました! を '<ビーンID = "contentNegotiationManager" クラス= "org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <プロパティ名= "favorPathExtension" 値:'ばねAPI-servlet.xml'が働いに次を追加= true "/> <プロパティ名=" ignoreAcceptHeader "value =" true "/> "/> –

+0

答えに私のコメントを反転させていただきありがとうございました! – Taylor

答えて

0

わからないが、これはおそらく、コンテンツタイプの交渉事です。 spring.io/blog/2013/05/11/content-negotiation-using-spring-mvcには、高いレベルの記述があります。春の増分では、春は時にはメッセージ変換プログラムを操作したり並べ替えたりします。つまり、要求受け入れヘッダーが広い場合には、「勝ち」が非特定です。

関連する問題