要配置RestTemplate的超时时间,可以在Spring Boot应用程序的配置文件中进行如下配置:
# 连接超时时间(毫秒)
spring.http.client.connect-timeout=5000
# 读取超时时间(毫秒)
spring.http.client.read-timeout=5000
然后,使用@Autowired注入RestTemplate bean,就可以在代码中使用了。
例如:
@Autowiredprivate RestTemplate restTemplate;
// ...
ResponseEntity<String> response = restTemplate.exchange(
"https://example.com/api/endpoint",
HttpMethod.