2012-07-12 4 views
0

나는 자동적으로 직렬화 및 JAXB 사용하여 객체를 직렬화 복원하는 간단한 웹 서비스 작성하려고 해요 :봄 3, JAXB

@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> 

I을 실제로 요청을하면 다음과 같이 표시됩니다.

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(). 

스프링에서 로그가 반환되지 않아 근본 원인을 파악하기가 어렵습니다. 이 과정에서 내가 누락 된 중요한 단계가 있습니까?

답변

0

일반적으로 요청에 "application/xml"이라는 Accept 헤더 또는 Content Type 헤더가 없기 때문입니다.

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

그래, 나는뿐만 아니라 내'curl' 요청을 수정하는 데 필요한 : 당신은 봄 3.1을 사용하고 또한 경우에, 당신은 당신의 주석이 더욱 명시 적으로 이런 식으로 할 수있다'-X POST는 ""-d 컬 - H "Content-Type : application/xml"http : // localhost : 9080/submit'. 봄이 얼마나 구체적인 지 잊어 버렸습니다. –