首页 > 解决方案 > Spring RestTemplate 没有为空响应释放连接

问题描述

我有一个 spring-boot 应用程序进行一堆 REST 后端调用。Rest 后端之一是抛出 ConnectionPoolTimeoutException。经过进一步调查,我怀疑当响应为错误或为空时,该后端的连接没有关闭。

尝试调试 Spring RestTemplate 代码,看到一行:

finally {
            if (response != null) {
                response.close();
            }
        }

如果响应为空,这看起来不会关闭连接。有没有人遇到过类似的问题,解决方法是什么。我正在考虑编写一个始终关闭连接的拦截器

标签: springspring-bootrestjava-8resttemplate

解决方案


推荐阅读