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
This commit is contained in:
parent
ffe994335e
commit
58e886fddf
|
|
@ -62,7 +62,6 @@ import org.springframework.context.ResourceLoaderAware;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
|
|
@ -180,7 +179,7 @@ public class WebMvcAutoConfiguration {
|
||||||
|
|
||||||
private final ListableBeanFactory beanFactory;
|
private final ListableBeanFactory beanFactory;
|
||||||
|
|
||||||
private final HttpMessageConverters messageConverters;
|
private final ObjectProvider<HttpMessageConverters> messageConvertersProvider;
|
||||||
|
|
||||||
final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer;
|
final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer;
|
||||||
|
|
||||||
|
|
@ -188,12 +187,12 @@ public class WebMvcAutoConfiguration {
|
||||||
|
|
||||||
public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties,
|
public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties,
|
||||||
WebMvcProperties mvcProperties, ListableBeanFactory beanFactory,
|
WebMvcProperties mvcProperties, ListableBeanFactory beanFactory,
|
||||||
@Lazy HttpMessageConverters messageConverters,
|
ObjectProvider<HttpMessageConverters> messageConvertersProvider,
|
||||||
ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizerProvider) {
|
ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizerProvider) {
|
||||||
this.resourceProperties = resourceProperties;
|
this.resourceProperties = resourceProperties;
|
||||||
this.mvcProperties = mvcProperties;
|
this.mvcProperties = mvcProperties;
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
this.messageConverters = messageConverters;
|
this.messageConvertersProvider = messageConvertersProvider;
|
||||||
this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider
|
this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider
|
||||||
.getIfAvailable();
|
.getIfAvailable();
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +204,8 @@ public class WebMvcAutoConfiguration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
converters.addAll(this.messageConverters.getConverters());
|
this.messageConvertersProvider.ifAvailable((customConverters) -> converters
|
||||||
|
.addAll(customConverters.getConverters()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue