Spring Boot Application - what is default timeout for any rest API endpoint or a easy config to control all endpoint timeout

后端 未结 4 653
长发绾君心
长发绾君心 2020-12-15 10:45

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

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 11:18

    There are a couple of ways to do this:

    1) Using ClientHttpRequestFactory with RestTemplate:

    public RestTemplate restTemplate() {
        return new RestTemplate(clientHttpRequestFactory());
    }
    
    private ClientHttpRequestFactory clientHttpRequestFactory() {
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setReadTimeout(timeinMillis);
        factory.setConnectTimeout(timeinMillis);
        return factory;
    }
    

    2) Second way is to use callable but I guess you have already explored that solution.

提交回复
热议问题