我已经配置了spring来为我们的API解析xml和json响应,如下所示:
<!-- oxm integration -->
<bean id="objectXmlMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller" />
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="ignoreAcceptHeader" value="false" />
<property name="favorPathExtension" value="true" />
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller" ref="objectXmlMarshaller" />
</bean>
</list>
</property>
</bean>不幸的是,spring使用application/*+xml返回xml响应。chrome似乎无法打开这些扩展,并将其发送到windows来打开它们(因此,我必须通过windows打开它,而不是在浏览器上看到响应)。
有人知道为什么它返回application/*+xml而不是配置的application/xml吗?
如果没有,有人知道如何强制chrome显示它吗?
谢谢!
发布于 2012-09-30 16:16:51
我发现解决这个问题的唯一方法是直接将控制器映射到所需的:
@RequestMapping(produces = { "application/json", "application/xml" })太糟糕了,spring不允许你有一个全局的定义。
https://stackoverflow.com/questions/11692642
复制相似问题