Spring RestClient异常:没有为响应类型找到合适的HttpMessageConverter

时间:2015-10-12 23:03:16

标签: spring rest jsf serialization jsf-2

我有一个Response类ResulResponse:

@JsonIgnoreProperties(ignoreUnknown = true)
public class MyResponse implements Serializable {
    private Map<Attribute, String> personalData;
    //Getters + Setters
}

包含属性映射(复杂对象):

@JsonIgnoreProperties(ignoreUnknown = true)
public class Attribute<T> implements Serializable {
    private AttributeName attributeName;
    private T attributeValue;
    //Getters + Setters
}

在属性中,我有一个属性AttributeName,它是一个枚举:

public enum AttributeName {
ATTRIBUTE_1,
ATTRIBUTE_2,
ATTRIBUTE_3
}

在属性中,属性Value可以是不同类型的对象(字符串,复杂对象等)

当我使用Spring Template调用REST服务时:

public MyRequest getResponse(){
    MyRequest request = new MyRequest();
    request.setSession("123");
    String uri = "http://localhost:8090/getResult";
    RestTemplate restTemplate = new RestTemplate();
    MyResponse response =  restTemplate.postForObject(uri, request, MyResponse.class);
    return response;
}

然后我得到了这个例外:我该如何解决这个问题?

2015-10-13 00:41:49.204 ERROR 396 --- [nio-8091-exec-1] o.a.c.c.C.[.[.[/].[FacesServlet]         : Servlet.service() for servlet [FacesServlet] in context with path [] threw exception [Error creating bean with name 'happyEnd' defined in file [C:\Users\Pluto\IdeaProjects\Client_Demo\target\classes\client\managedBeans\HappyEndBean.class]: Instantiation of bean failed; nested exception is      org.springframework.beans.BeanInstantiationException: Failed to instantiate [client.managedBeans.HappyEndBean]: Constructor threw exception; nested exception is org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class model.GetResultResponse] and content type [application/json;charset=UTF-8]] with root cause
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class model.GetResultResponse] and content type [application/json;charset=UTF-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:109) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:599) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:357) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at client.managedBeans.HappyEndBean.useId(HappyEndBean.java:64) ~[classes/:na]
at client.managedBeans.HappyEndBean.<init>(HappyEndBean.java:44) ~[classes/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_60]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_60]
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_60]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:344) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:44) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:339) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1045) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:55) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) ~[jsf-impl-2.2.12.jar:2.2.12]
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:80) ~[tomcat-embed-el-8.0.26.jar:8.0.26]
at org.apache.el.parser.AstValue.getValue(AstValue.java:137) ~[tomcat-embed-el-8.0.26.jar:8.0.26]
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) ~[tomcat-embed-el-8.0.26.jar:8.0.26]
at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:238) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:154) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183) ~[jsf-impl-2.2.12.jar:2.2.12]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) ~[jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) ~[jsf-api-2.2.12.jar:2.2]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) ~[jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) ~[jsf-impl-2.2.12.jar:2.2.12]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) ~[jsf-api-2.2.12.jar:2.2]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.26.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) ~[tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526) [tomcat-embed-core-8.0.26.jar:8.0.26]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482) [tomcat-embed-core-8.0.26.jar:8.0.26]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.26.jar:8.0.26]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

0 个答案:

没有答案