SpringMVCを使用して標準のJavaWebアプリケーションを開発し、最近3.0.6から3.2.0へのアップグレードを試みました。ほぼすべてのサーブレット応答はJSPまたはJsonビューですが、拡張子が「pdf」のpdfリクエストであるものもあります。
Spring 3.0.6では、SpringMVCドキュメントから取得したこの設定が行われました。
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="pdf" value="application/pdf"/>
<entry key="html" value="text/html"/>
<entry key="json" value="application/json"/>
</map>
これは、XMLViewResolverと組み合わせて正常に機能しました。
3.2.0にアップデートした後、失敗があります:
Error creating bean with name' org.springframework.web.servlet.view.ContentNegotiatingViewResolver#0' defined in class path resource [dispatcher-test-servlet.xml]: Invocation of init method failed; nested exception is
java.lang.ClassCastException: java.lang.String cannot be cast to org.springframework.http.MediaType'
ドキュメントといくつかのブログを調査した後、この構成は機能しているようです。
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="contentNegotiationManager">
<bean class="org.springframework.web.accept.ContentNegotiationManager">
<constructor-arg>
<list>
<!-- These are evaluated in order -->
<!-- Is there a media type based on suffix? -->
<bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
<constructor-arg>
<map>
<entry key="html" value="text/html" />
<entry key="json" value="application/json" />
<entry key="pdf" value="application/pdf" />
</map>
</constructor-arg>
</bean>
<!-- Else use request header -->
<bean
class="org.springframework.web.accept.HeaderContentNegotiationStrategy">
</bean>
</list>
</constructor-arg>
</bean>
</property>
しかし、この構成を使用して新しいSpring MVCテストフレームワークを実行しようとしましたが、ClassCast例外が再度発生したため、テストフレームワークはアプリケーションの実行時と同じようにBeanを初期化していないようです... Spring 3,2でContentNegotiatingViewResolverを堅牢な方法で構成する方法の明確な説明はありますか?ありがとう
リチャード