我是否需要关闭Response.body以在Feign Client中进行自定义错误处理

时间:2018-10-19 16:39:42

标签: netflix-feign spring-cloud-feign feign

我已参考此wiki页为Feign Client定义了自定义ErrorDecoder

在我的ErrorDecoder中,我正在通过调用response.body()

阅读响应正文

阅读close时,我是否需要ErrorDecoder在我的InputStream中做出回应。还是Feign将处理response的结案?

我检查了SynchronousMethodHandler,它调用了自定义错误解码器。这具有finally

} finally {
    if (shouldClose) {
        Util.ensureClosed(response.body());
}

因为Wiki页面上没有准则。

1 个答案:

答案 0 :(得分:0)

如果您直接阅读Response对象,您必须自己关闭身体,我们将泄漏资源。如果您返回Response对象作为Feign接口的一部分,则也是如此。