org.springframework.web.client.RestClientException: Could not extract response

sping boot project using remote call RestTemplate reported the following error:

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.Map] and content type [text/html;charset=utf-8]

Because I modified the code is already on the line here do not provide error rollback example, here provides an idea. . . , The track number of the underlying source code comparison, will find this reason given is built RestTemplate HttpMessageConverter several objects, without the support of this type of text html HttpMessageConverter /, so there is no way to obtain a corresponding respective objects HttpMessageConverter return The result of the conversion.

Solution:
Custom a converter, provides support for the type of error

Here Insert Picture Description
There are marked red frame of some type of converter, the source of their look, refer to, or directly Baidu oriented programming, can write a custom converter, and then applied to a custom converter RestTemplate the HttpMessageConverter collection:

List<HttpMessageConverter<?>> messageConverterList = restTemplate.getMessageConverters();

messageConverterList.add(自定义转换器);

By adding a custom converter, the error is solved.

Published 297 original articles · won praise 311 · views 50000 +

Guess you like

Origin blog.csdn.net/weixin_38106322/article/details/105199976