Remove @Lazy injection for HttpMessageConverters

This commit turns a lazy injection point for `HttpMessageConverters`
into an `ObjectProvider`-backed injection.

This allows to lazily rely on that bean without creating for it; in some
environments, such proxy creation can lead to issues like SPR-16990.

See gh-13785
pull/13815/head
Brian Clozel 6 years ago
parent ffe994335e
commit 58e886fddf

@ -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<HttpMessageConverters> messageConvertersProvider;
final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer;
@ -188,12 +187,12 @@ public class WebMvcAutoConfiguration {
public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties,
WebMvcProperties mvcProperties, ListableBeanFactory beanFactory,
@Lazy HttpMessageConverters messageConverters,
ObjectProvider<HttpMessageConverters> messageConvertersProvider,
ObjectProvider<ResourceHandlerRegistrationCustomizer> 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<HttpMessageConverter<?>> converters) {
converters.addAll(this.messageConverters.getConverters());
this.messageConvertersProvider.ifAvailable((customConverters) -> converters
.addAll(customConverters.getConverters()));
}
@Override

Loading…
Cancel
Save