Remove use of Ordered from auto-configuration classes
Closes gh-4056
This commit is contained in:
parent
89ed2aa020
commit
953ef7091b
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jdbc;
|
|||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
|
|
@ -38,15 +39,12 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||
*
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ JdbcTemplate.class, PlatformTransactionManager.class })
|
||||
public class DataSourceTransactionManagerAutoConfiguration implements Ordered {
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
|
||||
public class DataSourceTransactionManagerAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private DataSource dataSource;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ import org.springframework.web.servlet.view.BeanNameViewResolver;
|
|||
import org.springframework.web.util.HtmlUtils;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} to render errors via a MVC error
|
||||
* {@link EnableAutoConfiguration Auto-configuration} to render errors via an MVC error
|
||||
* controller.
|
||||
*
|
||||
* @author Dave Syer
|
||||
|
|
@ -72,17 +72,10 @@ import org.springframework.web.util.HtmlUtils;
|
|||
@AutoConfigureBefore(WebMvcAutoConfiguration.class)
|
||||
@EnableConfigurationProperties(ErrorProperties.class)
|
||||
@Configuration
|
||||
public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustomizer,
|
||||
Ordered {
|
||||
|
||||
public class ErrorMvcAutoConfiguration {
|
||||
@Autowired
|
||||
private ServerProperties properties;
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
|
||||
public DefaultErrorAttributes errorAttributes() {
|
||||
|
|
@ -95,10 +88,9 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
|
|||
return new BasicErrorController(errorAttributes, this.properties.getError());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
container.addErrorPages(new ErrorPage(this.properties.getServletPrefix()
|
||||
+ this.properties.getError().getPath()));
|
||||
@Bean
|
||||
public ErrorPageCustomizer errorPageCustomizer() {
|
||||
return new ErrorPageCustomizer(this.properties);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
@ -224,4 +216,30 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link EmbeddedServletContainerCustomizer} that configures the container's error
|
||||
* pages.
|
||||
*/
|
||||
private static class ErrorPageCustomizer implements
|
||||
EmbeddedServletContainerCustomizer, Ordered {
|
||||
|
||||
private final ServerProperties properties;
|
||||
|
||||
protected ErrorPageCustomizer(ServerProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
container.addErrorPages(new ErrorPage(this.properties.getServletPrefix()
|
||||
+ this.properties.getError().getPath()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -37,19 +37,12 @@ import org.springframework.util.StringUtils;
|
|||
* {@link ConfigurableEmbeddedServletContainer} from a {@link ServerProperties} bean.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@ConditionalOnWebApplication
|
||||
public class ServerPropertiesAutoConfiguration implements ApplicationContextAware,
|
||||
EmbeddedServletContainerCustomizer, Ordered {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
public class ServerPropertiesAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
|
||||
|
|
@ -57,22 +50,44 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar
|
|||
return new ServerProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
@Bean
|
||||
public DuplicateServerPropertiesDetector duplicateServerPropertiesDetector() {
|
||||
return new DuplicateServerPropertiesDetector();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
// ServerProperties handles customization, this just checks we only have
|
||||
// a single bean
|
||||
String[] serverPropertiesBeans = this.applicationContext
|
||||
.getBeanNamesForType(ServerProperties.class);
|
||||
Assert.state(
|
||||
serverPropertiesBeans.length == 1,
|
||||
"Multiple ServerProperties beans registered "
|
||||
+ StringUtils.arrayToCommaDelimitedString(serverPropertiesBeans));
|
||||
/**
|
||||
* {@link EmbeddedServletContainerCustomizer} that ensures there is exactly one
|
||||
* {@link ServerProperties} bean in the application context.
|
||||
*/
|
||||
private static class DuplicateServerPropertiesDetector implements
|
||||
EmbeddedServletContainerCustomizer, Ordered, ApplicationContextAware {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
// ServerProperties handles customization, this just checks we only have
|
||||
// a single bean
|
||||
String[] serverPropertiesBeans = this.applicationContext
|
||||
.getBeanNamesForType(ServerProperties.class);
|
||||
Assert.state(
|
||||
serverPropertiesBeans.length == 1,
|
||||
"Multiple ServerProperties beans registered "
|
||||
+ StringUtils
|
||||
.arrayToCommaDelimitedString(serverPropertiesBeans));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue