Web服务中的Spring3和JAXB

Web服务中的Spring3和JAXB,spring,jaxb,spring-ws,Spring,Jaxb,Spring Ws,我正在尝试编写一个简单的web服务,它使用JAXB自动序列化和反序列化对象: @XmlRootElement public class SimpleObject { private int id; private String name; /* ... */ } 我没有从Spring得到任何日志,这使得我很难确定根本原因。在这个过程中是否有我遗漏的关键步骤?通常这是因为您的请求中缺少“application/xml”的Accept头或Content-Type头

我正在尝试编写一个简单的web服务,它使用JAXB自动序列化和反序列化对象:

@XmlRootElement
public class SimpleObject {

    private int id;

    private String name;

    /* ... */
}



我没有从Spring得到任何日志,这使得我很难确定根本原因。在这个过程中是否有我遗漏的关键步骤?

通常这是因为您的请求中缺少“application/xml”的Accept头或Content-Type头。此外,如果您使用的是Spring 3.1,则可以通过以下方式使注释更加明确:

@RequestMapping(value="submit",method=RequestMethod.POST, consumes="application/xml", produces="application/xml")

是的,我还需要修改我的
curl
请求:
curl-xpost-d”“-H”内容类型:application/xml”http://localhost:9080/submit
。忘了春天有多特别。
<?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 ().
@RequestMapping(value="submit",method=RequestMethod.POST, consumes="application/xml", produces="application/xml")