关于java:RestClientException-Could-not-extract-response

11次阅读

共计 510 个字符,预计需要花费 2 分钟才能阅读完成。

谬误形容

在应用 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>
正文完
 0