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

后端 未结 4 652
长发绾君心
长发绾君心 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:28

    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;
        }
    

提交回复
热议问题