Remove use of field injection from ErrorMvcAutoConfiguration
This commit is contained in:
parent
5560af735c
commit
fdccd8aaa7
|
|
@ -27,7 +27,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
|
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
|
@ -82,20 +82,14 @@ import org.springframework.web.util.HtmlUtils;
|
||||||
@EnableConfigurationProperties(ResourceProperties.class)
|
@EnableConfigurationProperties(ResourceProperties.class)
|
||||||
public class ErrorMvcAutoConfiguration {
|
public class ErrorMvcAutoConfiguration {
|
||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
|
||||||
|
|
||||||
private final ServerProperties serverProperties;
|
private final ServerProperties serverProperties;
|
||||||
|
|
||||||
private final ResourceProperties resourceProperties;
|
private final List<ErrorViewResolver> errorViewResolvers;
|
||||||
|
|
||||||
@Autowired(required = false)
|
public ErrorMvcAutoConfiguration(ServerProperties serverProperties,
|
||||||
private List<ErrorViewResolver> errorViewResolvers;
|
ObjectProvider<List<ErrorViewResolver>> errorViewResolversProvider) {
|
||||||
|
|
||||||
public ErrorMvcAutoConfiguration(ApplicationContext applicationContext,
|
|
||||||
ServerProperties serverProperties, ResourceProperties resourceProperties) {
|
|
||||||
this.applicationContext = applicationContext;
|
|
||||||
this.serverProperties = serverProperties;
|
this.serverProperties = serverProperties;
|
||||||
this.resourceProperties = resourceProperties;
|
this.errorViewResolvers = errorViewResolversProvider.getIfAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -116,19 +110,34 @@ public class ErrorMvcAutoConfiguration {
|
||||||
return new ErrorPageCustomizer(this.serverProperties);
|
return new ErrorPageCustomizer(this.serverProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnBean(DispatcherServlet.class)
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public DefaultErrorViewResolver conventionErrorViewResolver() {
|
|
||||||
return new DefaultErrorViewResolver(this.applicationContext,
|
|
||||||
this.resourceProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public static PreserveErrorControllerTargetClassPostProcessor preserveErrorControllerTargetClassPostProcessor() {
|
public static PreserveErrorControllerTargetClassPostProcessor preserveErrorControllerTargetClassPostProcessor() {
|
||||||
return new PreserveErrorControllerTargetClassPostProcessor();
|
return new PreserveErrorControllerTargetClassPostProcessor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class DefaultErrorViewResolverConfiguration {
|
||||||
|
|
||||||
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
private final ResourceProperties resourceProperties;
|
||||||
|
|
||||||
|
DefaultErrorViewResolverConfiguration(ApplicationContext applicationContext,
|
||||||
|
ResourceProperties resourceProperties) {
|
||||||
|
this.applicationContext = applicationContext;
|
||||||
|
this.resourceProperties = resourceProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(DispatcherServlet.class)
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public DefaultErrorViewResolver conventionErrorViewResolver() {
|
||||||
|
return new DefaultErrorViewResolver(this.applicationContext,
|
||||||
|
this.resourceProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "server.error.whitelabel", name = "enabled", matchIfMissing = true)
|
@ConditionalOnProperty(prefix = "server.error.whitelabel", name = "enabled", matchIfMissing = true)
|
||||||
@Conditional(ErrorTemplateMissingCondition.class)
|
@Conditional(ErrorTemplateMissingCondition.class)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue