diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index 4299cd148a..b970716163 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -62,7 +62,6 @@ import org.springframework.context.ResourceLoaderAware; 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.annotation.Order; @@ -180,7 +179,7 @@ public class WebMvcAutoConfiguration { private final ListableBeanFactory beanFactory; - private final HttpMessageConverters messageConverters; + private final ObjectProvider messageConvertersProvider; final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer; @@ -188,12 +187,12 @@ public class WebMvcAutoConfiguration { public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties, WebMvcProperties mvcProperties, ListableBeanFactory beanFactory, - @Lazy HttpMessageConverters messageConverters, + ObjectProvider messageConvertersProvider, ObjectProvider resourceHandlerRegistrationCustomizerProvider) { this.resourceProperties = resourceProperties; this.mvcProperties = mvcProperties; this.beanFactory = beanFactory; - this.messageConverters = messageConverters; + this.messageConvertersProvider = messageConvertersProvider; this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider .getIfAvailable(); } @@ -205,7 +204,8 @@ public class WebMvcAutoConfiguration { @Override public void configureMessageConverters(List> converters) { - converters.addAll(this.messageConverters.getConverters()); + this.messageConvertersProvider.ifAvailable((customConverters) -> converters + .addAll(customConverters.getConverters())); } @Override