一、报错
Could not extract response: no suitable HttpMessageConverter found for response type [xxx] and content type [application/octet-stream]
feign.codec.DecodeException: Could not extract response: no suitable HttpMessageConverter found for response type [xxx] and content type [application/octet-stream]
解释一下:就是Feign自带的转换器中,无法把[class XXX]转换成content type [XXX;XXX]
- 在使用SpringCloud FeignClient的时候,经常的情况是我们希望返回的是一个application/json类型的返回,
- 当返回是[application/octet-stream]类型或者其他自带转换器中没有的类型时,feign调用就会解析错误。
二、具体源码分析
(1)在 Springboot 默认处理器为 MappingJackson2HttpMessageConverter
用于将 Java 对象转换为 JSON 格式。
但是
MappingJackson2HttpMessageConverter,
只支持"application/json"类型;因此springboot没有找到合适的HttpMessageConverter
,于是报出了上面的异常。