错误描述

在使用spring - RestTemplate 时出现以下错误:

org.springframework.web.client RestClientException: Could not extract response : no suitable HttpMessageConverter found for request type [java.util.HasMap]

错误原因

第一种原因

发送请求返回的是text/html,而restTemplate不能将这种类型转换成json.

遇到这种错误首先考虑第一种原因,一般请求服务端时,发生错误,如:400,401,404,500...等状态返回的都是html,因为restTemplate不能将html类型转换成json,所以抛出此异常.

第二种原因

响应类型就是json,但是缺少一个jackson的依赖

解决方法就是引入依赖:

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

Sugar
11 声望0 粉丝

« 上一篇
笔记