diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index 1428f80d31..cdd704cde6 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -52,6 +52,7 @@ import org.springframework.boot.web.filter.OrderedRequestContextFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Primary; import org.springframework.core.Ordered; import org.springframework.core.convert.converter.Converter; @@ -170,7 +171,7 @@ public class WebMvcAutoConfiguration { public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties, WebMvcProperties mvcProperties, ListableBeanFactory beanFactory, - HttpMessageConverters messageConverters, + @Lazy HttpMessageConverters messageConverters, ObjectProvider resourceHandlerRegistrationCustomizerProvider) { this.resourceProperties = resourceProperties; this.mvcProperties = mvcProperties; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java index 2ab36dccc3..aa89133a82 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java @@ -51,11 +51,13 @@ import org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.core.convert.ConversionService; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.http.converter.HttpMessageConverter; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.MockMvc; @@ -760,6 +762,11 @@ public class WebMvcAutoConfigurationTests { .isSameAs(this.context.getBean("customJsr303Validator")); } + @Test + public void httpMessageConverterThatUsesConversionServiceDoesNotCreateACycle() { + load(CustomHttpMessageConverter.class); + } + private void load(Class config, String... environment) { load(config, null, environment); } @@ -990,4 +997,15 @@ public class WebMvcAutoConfigurationTests { } + @Configuration + static class CustomHttpMessageConverter { + + @Bean + public HttpMessageConverter customHttpMessageConverter( + ConversionService conversionService) { + return mock(HttpMessageConverter.class); + } + + } + }