简体   繁体   English

无法提取响应:找不到合适的HttpMessageConverter

[英]Could not extract response: no suitable HttpMessageConverter found

I am writing a spring mvc app(Spring newbie) which has to call a rest service. 我正在写一个春季mvc应用程序(Spring新手),它必须调用休息服务。 I have the rest service deployed in my VM(weblogic 10.3.6 in Linux) and the app I am writing is in my local laptop weblogic(10.3.6 in Windows 8.1). 我在我的VM中部署了其余服务(Linux中的weblogic 10.3.6),我正在编写的应用程序位于我的本地笔记本电脑weblogic(Windows 8.1中的10.3.6)中。

When I try calling the rest service the request goes fine to the restservice app, but the response fails with the following message 当我尝试调用其余服务时,请求适用于restservice应用程序,但响应失败并显示以下消息

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.myclass.Acct] and content type [application/json;charset=UTF-8]
        at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:110)
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:572)

I am initializing the rest client in my controller & calling a method as below 我正在我的控制器中初始化其余客户端并调用如下方法

Class1 ccc = new Class1();
Client client = new Client("REST URL","key","key1","USR",ccc);
client.getService("String"));

In the actual client, the call to rest service looks like this 在实际的客户端中,对休息服务的调用如下所示

Acct acct1 = restClient.getRestTemplate().getForObject("URL", Acct.class, "USR");

The error I get is here in the above line. 我得到的错误在上面的行中。 I am not sure how to set the response type. 我不知道如何设置响应类型。 When I change the Acct.class to String.class and Acct acct1 to Object acct1, then it works. 当我将Acct.class更改为String.class并将Acct acct1更改为Object acct1时,它可以正常工作。

Do I need to set anything in my dispatcher-servlet.xml for the response type json? 我是否需要在我的dispatcher-servlet.xml中为响应类型json设置任何内容? Let me know if any other configurations are needed to make this work. 让我知道是否需要任何其他配置才能使其工作。 I did look at other posts related to this, but it did not help. 我确实看过与此相关的其他帖子,但没有帮助。 Thanks. 谢谢。

Thanks for the help. 谢谢您的帮助。 I have solved the issue and it is working now. 我已经解决了这个问题,现在正在运作。

I made the following updates: 我做了以下更新:

in my pom.xml 在我的pom.xml中

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.5.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.5.3</version>
</dependency>

in my dispatcher servlet 在我的调度程序servlet中

<!-- Configure to plugin JSON as request and response in method handler -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="jsonMessageConverter"/>
            </list>
        </property>
    </bean>

    <!-- Configure bean to convert JSON to POJO and vice versa -->
    <bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
    </bean> 

in my code(Acct class) 在我的代码中(Acct类)

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
...........
..........
 @JsonIgnore
 @JsonProperty(value = "........")
 public Set getMethod()
 {
     return this.............;
 }

Now, I am able to get the results from the rest services. 现在,我可以从其他服务中获得结果。

Thanks. 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android版Spring-无法提取响应:找不到适合响应类型的HttpMessageConverter - Spring for Android - Could not extract response: no suitable HttpMessageConverter found for response type RestClientException无法提取响应:找不到合适的HttpMessageConverter作为响应类型 - RestClientException Could not extract response: no suitable HttpMessageConverter found for response type Spring Rest客户端实现:无法提取响应:没有为xstreamMarshaller找到适合的响应类型的HttpMessageConverter - Spring Rest Client implementation : Could not extract response: no suitable HttpMessageConverter found for response type with xstreamMarshaller 无法提取响应:没有找到适合响应类型 class 和内容类型 [text/html] 的 HttpMessageConverter - Could not extract response: no suitable HttpMessageConverter found for response type class and content type [text/html] 无法提取响应:jaxb2marshaller没有合适的HttpMessageConverter - Could not extract response: no suitable HttpMessageConverter with jaxb2marshaller 休息模板:无法提取响应:当我们得到 xml 响应时,没有找到适合响应类型的 HttpMessageConverter,未绑定到 JAVA 对象 - Rest Template:Could not extract response: no suitable HttpMessageConverter found for response type when we got xml response, not bind to JAVA object 没有找到适合响应类型的 HttpMessageConverter - no suitable HttpMessageConverter found for response type HttpMessageConverter 异常:RestClientException:无法写入请求:找不到合适的 HttpMessageConverter - HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found 转换JSON响应时找不到合适的HttpMessageConverter? - No suitable HttpMessageConverter found when converting JSON response? 没有为响应类型找到合适的HttpMessageConverter - Custom RestTemplate - No suitable HttpMessageConverter found for response type - Custom RestTemplate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM