问题描述
在springboot 2的版本中通过feign进行调用,在引入私服jar包并进行调用时,报错:
feign.codec.DecodeException: Could not extract response: no suitable HttpMessageConverter found for response type [xxx.Response<com.xxx.XxxResponseDto>] and content type [application/octet-stream;charset=utf-8]
其中,Response是返回报文实体类,XxxResponseDto是返回报文中的响应体(body部分),返回报文分为head和body两部分,如下
{
"head": {
"retFlag": "00000",
"retMsg": "成功"
},
"body": {
"data": {
// 报文数据
}
}
}
分析原因
暂无
解决方法
首先,调用时在请求头header中添加Content-Type = application/json,不行!
其次,像下边的代码一样添加consumes和produces属性
@FeignClient(name = "服务实例名")
public interface XxxClient {
@PostMapping(value = "/x/x/x/x", consumes = "application/json;charset=utf-8", produces = "application/json;charset=utf-8")
Response<XxxResponseDto> getXXX(@Valid @RequestBody XxxRequestDto requestDto);
}
在加上之后还是不行!
后来,直接用postman调用url为“/x/x/x/x”的接口,发现调不通了,在解决单独调接口调不通这个问题后,再次通过之前的方式调用,可以调通了。