-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Ken Egervari opened SPR-6130 and commented
I'm having a problem where I am trying to get xml, json, html, etc. to work using the content negotiator. It works perfectly... almost. The main problem I'm having is that the default content type is coming up as XML. Here is the dispatcher servlet xml:
<bean id="contentNegotiatingViewResolver"
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="2"/>
<property name="mediaTypes">
<map>
<entry key="ftl" value="text/html"/>
<entry key="xml" value="application/xml"/>
<entry key="json" value="application/json"/>
<entry key="atom" value="application/atom+xml"/>
<entry key="rss" value="application/rss+xml"/>
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller">
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true"/>
</bean>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
</list>
</property>
<property name="viewResolvers">
<list>
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="1"/>
<property name="cache" value="false"/>
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
<property name="exposeSpringMacroHelpers" value="true"/>
</bean>
</list>
</property>
</bean>
As it stands, mapping to "/" results in Spring trying to get to "/.xml", which is terrible since it really needs to get mapped to what I have in @RequestMapping
in a controller (mine points to "index", which in turns should get mapped to "index.ftl" in the view resolver)
Ultimately though, despite the above mentioned problem, having to specify ".ftl" whenever I want a text/html view is somewhat annoying. It's workable mind you... but then there is no change of having a proper index page.
If there is quick workaround, would you please email me? Maybe I set it up incorrectly too... and if that's the case, I apologize for posting this.
Thanks for all of your help!
Affects: 3.0 M4
Reference URL: http://forum.springsource.org/showthread.php?p=261035#post261035
Issue Links:
- ContentNegotiatingViewResolver picks first media type from Accept header which is not consistent across browsers [SPR-5706] #10376 ContentNegotiatingViewResolver picks first media type from Accept header which is not consistent across browsers
Referenced from: commits 5faa4d9