When I use auto-configured bean of RestTemplateBuilder, the timeout field doesn't set as intended.
code:
public WebHookService(RestTemplateBuilder restTemplateBuilder) {
restTemplate = restTemplateBuilder
.setConnectTimeout(Duration.ofSeconds(10))
.setReadTimeout(Duration.ofSeconds(30))
.build();
However When I set the custom bean of RestTemplateBuilder, timeout is set as Intended.
code:
@Bean
RestTemplateBuilder restTemplateBuilder() {
return new RestTemplateBuilder();
}
// ...
public WebHookService(RestTemplateBuilder restTemplateBuilder) {
restTemplate = restTemplateBuilder
.setConnectTimeout(Duration.ofSeconds(10))
.setReadTimeout(Duration.ofSeconds(30))
.build();
As far as I know, In Spring Boot 1.4.0 application RestTemplateBuilder is available as a bean and you can simply use that.
So there should be no difference between using custom bean and auto-configured bean.
... But it didn't!
Anyone who knows why?


WebHookServiceand how is it created/managed? Also, what version of Spring Boot are you using?WebHookServiceclass is managed as@Service, and spring boot 3.1.0 is what I'm using.buildmethod, and see what it does. You didn't show at which point you're checking the timeout values, and depending on the lifecycle, that might matter. Your question lacks debugging details.