[英]Spring MVC 3.2: returning Document (xml) with @Responsebody
我是Spring MVC的新手,我有一个通常返回org.w3c.dom.Document对象(XML文档)的应用程序。 该文档具有许多不同的(动态的)结构(没有特定的xsd)。 我需要知道如何从控制器返回此对象。 例如
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public Document createFOO(Document myDoc){
return myDoc;
}
当我尝试这样做时,出现HTTP 406错误,显然我需要配置,但是我找不到解决我问题的文档,因为所有这些解决方案都包括类和XML之间的映射,但就我而言,对象已经是XML文档。 您能给我一个指导我进行调查的方向吗?
谢谢!
马科斯
编辑:这是我的配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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">
<context:component-scan base-package="my.files"/>
<mvc:annotation-driven/>
</beans>
我的示例课:
@Controller
@RequestMapping("blabla")
public class MyClass{
...
@RequestMapping(method = RequestMethod.POST, produces = "application/xml")
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public Document myMethod(...) {
Document responseDoc = foo.giveMeaDocument();
}
}
HTTP / 406错误是由于无法将文档对象映射到响应主体而造成的。
您将需要确保在XML配置或JavaConfig样式下的类似构造中使用<mvc:annotation-driven />。
编辑
我已经实现了一个快速且非常肮脏的应用程序,以演示我在说什么:
https://github.com/djgraff209/domconversion
看看是否满足您的需求-告知它非常粗糙,仅用于演示技术。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.