我有弹簧控制器:
@Controller
@RequestMapping(value="/fake_cp")
public class FakeContentProvider {
@RequestMapping(value="/request")
public @ResponseBody JAXBElement<MetaRequest> request(
@Valid @ModelAttribute FaceContentProviderCommand command
)
throws Exception {
ru.icb.cpaclick.controller.jaxb.MetaRequest request = new ru.icb.cpaclick.controller.jaxb.MetaRequest();
request.setAccessUrl("http://accessUrl.ru");
request.setErrorUrl("http://errorUrl.ru");
request.setShortdesc("This is short desc");
request.setLoadUrl("http://loadru.ru");
request.setTariffclass(20501);
return new ObjectFactory().createRequest(request);
}
服务器返回答案:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:993)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleHttpEntityResponse(AnnotationMethodHandlerAdapter.java:952)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:878)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Could not find acceptable representation
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
[application/octet-stream, */*, text/plain;charset=ISO-8859-1, */*, */*, application/xml, text/xml, application/*+xml, application/x-www-form-urlencoded, multipart/form-data, application/xml, text/xml, application/*+xml]
05.08.2011 10:57:08 org.apache.catalina.core.StandardContext reload
如何为jaxbelement创建响应转换器,或者如何配置spring?
答案 0 :(得分:0)
这可能不是在Spring中处理REST或SOAP服务的最佳方法。
spring mvc控制器最适合用于渲染网页。如果你想处理REST或SOAP服务,最好添加一个与Spring集成的Apache XCF servlet。
使用xjc(REST)和wsimport(SOAP),您可以使用契约优先方法生成与要公开的服务相关的类和接口。 基于此,您可以在xcf配置中创建一个端点并完成。