2012-07-12 62 views
0

我想写自动的序列化,并使用JAXB反序列化对象的一个​​简单的Web服务:弹簧3和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那里得到日志,这使我很难确定根本原因。在这个过程中,我缺少一个关键的步骤吗?

回答

0

通常,这是因为请求中缺少“application/xml”的Accept头或Content Type头。此外,如果你使用Spring 3.1,可以让你的注释更明确的是这样的:

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

是的,我需要修改我的'curl'要求以及:'卷曲-X POST -d“” - H“Content-Type:application/xml”http:// localhost:9080/submit'。忘记了Spring有多特殊。 – 2012-07-12 22:46:05