diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java index ce89524c27..70bc8c50c6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java @@ -45,7 +45,6 @@ public class RestTemplateAutoConfiguration { @Bean @Lazy - @ConditionalOnMissingBean public RestTemplateBuilderConfigurer restTemplateBuilderConfigurer( ObjectProvider messageConverters, ObjectProvider restTemplateCustomizers, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java index a80f93a737..8e576929f2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java @@ -21,6 +21,7 @@ import java.util.List; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.support.BeanDefinitionOverrideException; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration; @@ -65,6 +66,14 @@ class RestTemplateAutoConfigurationTests { .isTrue()); } + @Test + void shouldFailOnCustomRestTemplateBuilderConfigurer() { + this.contextRunner.withUserConfiguration(RestTemplateCustomConfigurerConfig.class) + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanDefinitionOverrideException.class) + .hasMessageContaining("with name 'restTemplateBuilderConfigurer'")); + } + @Test void restTemplateBuilderShouldBeLazilyDefined() { this.contextRunner @@ -263,6 +272,16 @@ class RestTemplateAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class RestTemplateCustomConfigurerConfig { + + @Bean + RestTemplateBuilderConfigurer restTemplateBuilderConfigurer() { + return new RestTemplateBuilderConfigurer(); + } + + } + static class CustomHttpMessageConverter extends StringHttpMessageConverter { }