spring boot 2 - set resttemplate timeout
Java[Edit]
+
0
-
0
Spring Boot 2 - set RestTemplate timeout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21package com.example.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; import java.time.Duration; @Configuration public class TemplateConfig { @Bean public RestTemplate restTemplate(@Autowired RestTemplateBuilder restTemplateBuilder) { return restTemplateBuilder .setConnectTimeout(Duration.ofSeconds(5)) // 5 seconds connection timeout .setReadTimeout(Duration.ofSeconds(5)) // 5 seconds reading timeout .build(); } }