Spring Boot应用程序 - 任何其他API端点的默认超时或控制所有端点超时的简单配置 [英] Spring Boot Application - what is default timeout for any rest API endpoint or a easy config to control all endpoint timeout

查看:111
本文介绍了Spring Boot应用程序 - 任何其他API端点的默认超时或控制所有端点超时的简单配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用当前的Spring启动版本(1.4.x),并想知道api调用是否有任何默认超时。我已经通过设置断点来测试它,但它一直在等待并且没有超时。
我还试图通过使用一些注释或yml设置为我的所有spring-boot应用程序配置默认超时。

I am using current Spring boot version (1.4.x) and wondering if it has any default timeout for api calls. I have tested it by putting breakpoints but it was keep waiting and didn't time-out. I was also trying to configure default timeout for all my spring-boot apps by using some annotation or yml settings.

我发现了几种替代品(其中一种这里)但是使用callable实际上添加了额外的非业务逻辑代码,其中在xml bean中设置某些东西在最新的Spring启动应用程序中已经过时了。

I found couple of alternatives (one of them here) but using callable actually adding extra non-business logic code where setting something in xml bean is out of fashion in latest spring boot applications.

推荐答案

我同意以上所有选项,并在我的春季启动应用程序中尝试了以下选项。它现在完美无缺。下面是作为bean的代码示例。现在只需要 @Autowire RestTemplate where( java class ) 我需要它。

I agree all above options and tried below option in my spring boot application. It works perfectly fine now. Below is the code sample as a bean. Now just need to @Autowire RestTemplate wherever(java class) I need it.

   @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        ((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setConnectTimeout(15000);
        ((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setReadTimeout(15000);

        return restTemplate;
    }

这篇关于Spring Boot应用程序 - 任何其他API端点的默认超时或控制所有端点超时的简单配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆