前言
spring cloud 对feign调用对返回值做了包装处理,通过一些列Decoder来处理feign访问的返回值。
具体流程 从SynchronousMethodHandler中的decoder开始会经历如下几个decoder:
OptionalDecoder -> ResponseEntityDecoder -> SpringDecoder
可以在 FeignClientsConfiguration 看到有对上面三个decoder的定义,有兴趣的可以自行阅读源码。
feign返回值拦截 + response只能读取一次处理
feign返回值拦截只需要自定义一个coder,替换 FeignClientsConfiguration 中的 decoder定义即可,具体代码如下:
配置自定义decoder:
/**
* feign返回值拦截
* @author liufei
*/
public final class ResultStatusDecoder implements Decoder {
public static final String CONTENT_KEY = "content"