【问题标题】:Spring rest template close connection if the data is more如果数据更多,Spring rest模板关闭连接
【发布时间】:2020-09-02 16:21:05
【问题描述】:

我有一个场景,如果服务器发送的数据比预期的多,则需要关闭 http 连接。即在接收数据几秒钟后,我想自动关闭连接。这可行吗?

【问题讨论】:

    标签: spring http resttemplate spring-resttemplate


    【解决方案1】:

    您可以在 RestTemplate 上指定超时。这样您就可以终止任何长时间运行的请求。

        @Bean
        public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) 
        {
            return restTemplateBuilder
               .setConnectTimeout(...)
               .setReadTimeout(...)
               .build();
        }
    

    【讨论】:

    • 我试过了,还是不行 - RestTemplate restTemplate = new RestTemplateBuilder().setConnectTimeout(Duration.ofSeconds(20)) .setReadTimeout(Duration.ofSeconds(20)).build();
    猜你喜欢
    • 2016-12-05
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 2012-01-06
    • 2021-01-05
    相关资源
    最近更新 更多