Add ContentNegotiationManagerFactoryBean

The new FactoryBean facilitates the creation of a
ContentNegotiationManager in XML configuration.

Issue: SPR-8420
This commit is contained in:
Rossen Stoyanchev
2012-07-21 06:16:42 -04:00
parent 028e15faa3
commit 64d939bb16
6 changed files with 342 additions and 39 deletions

View File

@@ -4503,25 +4503,20 @@ public class WebConfig extends WebMvcConfigurerAdapter {
}
}</programlisting>
<para>In XML you'll need to use the <code>content-negotiation-manager</code> property:</para>
<para>In XML you'll need to use the <code>content-negotiation-manager</code>
property of <code>annotation-driven</code>:</para>
<programlisting language="xml">&lt;mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" /&gt;
&lt;bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManager"&gt;
&lt;constructor-arg&gt;
&lt;list&gt;
&lt;ref bean="pathExtensionStrategy" /&gt;
&lt;bean id="headerStrategy" class="org.springframework.web.accept.HeaderContentNegotiationStrategy"/&gt;
&lt;/list&gt;
&lt;/constructor-arg&gt;
&lt;/bean&gt;
&lt;bean id="pathExtensionStrategy" class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy"&gt;
&lt;constructor-arg&gt;
&lt;map&gt;
&lt;entry key="xml" value="application/rss+xml" /&gt;
&lt;/map&gt;
&lt;/constructor-arg&gt;
&lt;bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"&gt;
&lt;property name="favorPathExtension" value="false" /&gt;
&lt;property name="favorParameter" value="true" /&gt;
&lt;property name="mediaTypes" &gt;
&lt;value&gt;
json=application/json
xml=application/xml
&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;</programlisting>
</section>