我试图编写一个使用JAXB自动序列化和反序列化对象的简单web服务:
@XmlRootElement
public class SimpleObject {
private int id;
private String name;
/* ... */
}@Controller
public class SimpleObjectController {
@RequestMapping("submit",method=RequestMethod.POST)
public String doPost(@RequestBody SimpleObject value) {
return value.toString();
}
}<?xml version="1.0"?>
<beans ...>
<oxm:jaxb2-marshaller id="marshaller" class="path.to.objects"/>
</beans>然而,当我实际提出请求时,我会得到以下内容:
HTTP Status 415
The server refused this request because the request entity is in a format not
supported by the requested resource for the requested method ().我没有从Spring获得任何日志,这使我很难确定根本原因。在这个过程中,我错过了一个关键的步骤吗?
发布于 2012-07-12 21:47:24
通常情况下,这是因为请求中缺少了"application/xml“的Accept标头或Content报头。另外,如果您使用Spring3.1,您可以通过这种方式使您的注释更加明确:
@RequestMapping(value="submit",method=RequestMethod.POST, consumes="application/xml", produces="application/xml")https://stackoverflow.com/questions/11460999
复制相似问题