I have a spring boot application which was running with Spring Boot 3.1.8. After upgrading Spring Boot version to 3.2.3, it started to complain about restClientBuilder bean. When I checked the RestClientAutoConfiguration
class coming from org.springframework.boot.autoconfigure.web.client
, I can see the ConditionalOnMissingBean annotation in bean definition.
@Bean
@Lazy
@ConditionalOnMissingBean
public RestTemplateBuilder restTemplateBuilder(RestTemplateBuilderConfigurer restTemplateBuilderConfigurer) {
RestTemplateBuilder builder = new RestTemplateBuilder(new RestTemplateCustomizer[0]);
return restTemplateBuilderConfigurer.configure(builder);
}
According to that implementation, having another bean with same name and type shouldn’t be a problem. I have an external dependency creating a bean with same name and type. Before upgrade everything was okey. What can be the reason for this situation?
The error that I have after upgrade:
The bean 'restClientBuilder', defined in class path resource [org/springframework/boot/autoconfigure/web/client/RestClientAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/self/external/ElasticsearchConfiguration.class] and overriding is disabled.
I don’t want to enable spring.main.allow-bean-definition-overriding
property to avoid some possible errors on other parts/