xml 콘텐츠가있는 "게시물"을 지원하는 간단한 스프링 기반 웹 서비스를 만들려고합니다. 봄xml to Spring REST 서버가 반환하는 지원되지 않는 미디어 유형
, 나는 AnnotationMethodHandler을 정의
<bean id="inboundMessageAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list>
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="xmlMarshaller"/>
<property name="unmarshaller" ref="xmlMarshaller"/>
</bean>
</util:list>
</property>
</bean>
그리고 JAXB 기반 XML 마샬 :
<bean id="xmlMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths">
<array>
<value>com.company.schema</value>
</array>
</property>
<property name="schemas">
<array>
<value>classpath:core.xsd</value>
</array>
</property>
</bean>
내 컨트롤러는 "자원이"JAXB에 의해 자동 생성 클래스이고, 다음과 같이 주석이 :
@RequestMapping(method = POST, value = "/resource")
public Resource createResource(@RequestBody Resource resource) {
// do work
}
웹 서비스 호출의 결과는 항상 "HTTP/1.1 415 지원되지 않음 Med ia 유형 ". 다음은 서비스 호출 예입니다.
HttpPost post = new HttpPost(uri);
post.addHeader("Accept", "application/xml");
post.addHeader("Content-Type", "application/xml");
StringEntity entity = new StringEntity(request, "UTF-8");
entity.setContentType("application/xml");
post.setEntity(entity);
가능한 모든 미디어 유형을 설정할 수 있습니다. 누구나 아이디어가 있습니까?
편집 : 추가 디버깅 후 객체를 비동기 해제하려고 시도하는 것처럼 보이지 않습니다. AnnotationMethodHandler가 application/xml 유형이 무언가 MarshallingHttpConverter에 가야한다는 것을 아는 뒤에있는 검은 마법을 이해하지 못합니다. 누구든지 그 빛을 비춰 줄 수 있습니까?
제안에 감사드립니다. skaffman. 나는 검사하고 클래스는 실제로 @XMLRootElement 태그를 가지고있다. –
@Mayra :'Resource'는'com.company.schema' 패키지에 있습니까? config로'Jaxb2Marshaller'를 구성하는 단위 테스트를 작성하고'support (Resource.class)'가'true'를 리턴하는지 확인하십시오. 당신이 더 이상 얻을 수 있기 전에 그것은 일할 필요가 있습니다. – skaffman
주사위가 없으므로 Jaxb2Marshaller 객체를 만들었고 springfile에있는 contextPath와 schema를 설정하고 클래스를 지원한다고 말했습니다. –