Commit 953ef709 authored by Andy Wilkinson's avatar Andy Wilkinson

Remove use of Ordered from auto-configuration classes

Closes gh-4056
parent 89ed2aa0
...@@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jdbc; ...@@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jdbc;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
...@@ -38,15 +39,12 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -38,15 +39,12 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
* *
* @author Dave Syer * @author Dave Syer
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Andy Wilkinson
*/ */
@Configuration @Configuration
@ConditionalOnClass({ JdbcTemplate.class, PlatformTransactionManager.class }) @ConditionalOnClass({ JdbcTemplate.class, PlatformTransactionManager.class })
public class DataSourceTransactionManagerAutoConfiguration implements Ordered { @AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
public class DataSourceTransactionManagerAutoConfiguration {
@Override
public int getOrder() {
return Integer.MAX_VALUE;
}
@Autowired(required = false) @Autowired(required = false)
private DataSource dataSource; private DataSource dataSource;
......
...@@ -58,7 +58,7 @@ import org.springframework.web.servlet.view.BeanNameViewResolver; ...@@ -58,7 +58,7 @@ import org.springframework.web.servlet.view.BeanNameViewResolver;
import org.springframework.web.util.HtmlUtils; 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. * controller.
* *
* @author Dave Syer * @author Dave Syer
...@@ -72,17 +72,10 @@ import org.springframework.web.util.HtmlUtils; ...@@ -72,17 +72,10 @@ import org.springframework.web.util.HtmlUtils;
@AutoConfigureBefore(WebMvcAutoConfiguration.class) @AutoConfigureBefore(WebMvcAutoConfiguration.class)
@EnableConfigurationProperties(ErrorProperties.class) @EnableConfigurationProperties(ErrorProperties.class)
@Configuration @Configuration
public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustomizer, public class ErrorMvcAutoConfiguration {
Ordered {
@Autowired @Autowired
private ServerProperties properties; private ServerProperties properties;
@Override
public int getOrder() {
return 0;
}
@Bean @Bean
@ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT) @ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
public DefaultErrorAttributes errorAttributes() { public DefaultErrorAttributes errorAttributes() {
...@@ -95,10 +88,9 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom ...@@ -95,10 +88,9 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
return new BasicErrorController(errorAttributes, this.properties.getError()); return new BasicErrorController(errorAttributes, this.properties.getError());
} }
@Override @Bean
public void customize(ConfigurableEmbeddedServletContainer container) { public ErrorPageCustomizer errorPageCustomizer() {
container.addErrorPages(new ErrorPage(this.properties.getServletPrefix() return new ErrorPageCustomizer(this.properties);
+ this.properties.getError().getPath()));
} }
@Configuration @Configuration
...@@ -224,4 +216,30 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom ...@@ -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;
}
}
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -37,19 +37,12 @@ import org.springframework.util.StringUtils; ...@@ -37,19 +37,12 @@ import org.springframework.util.StringUtils;
* {@link ConfigurableEmbeddedServletContainer} from a {@link ServerProperties} bean. * {@link ConfigurableEmbeddedServletContainer} from a {@link ServerProperties} bean.
* *
* @author Dave Syer * @author Dave Syer
* @author Andy Wilkinson
*/ */
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnWebApplication @ConditionalOnWebApplication
public class ServerPropertiesAutoConfiguration implements ApplicationContextAware, public class ServerPropertiesAutoConfiguration {
EmbeddedServletContainerCustomizer, Ordered {
private ApplicationContext applicationContext;
@Override
public int getOrder() {
return 0;
}
@Bean @Bean
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT) @ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
...@@ -57,22 +50,44 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar ...@@ -57,22 +50,44 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar
return new ServerProperties(); return new ServerProperties();
} }
@Override @Bean
public void setApplicationContext(ApplicationContext applicationContext) public DuplicateServerPropertiesDetector duplicateServerPropertiesDetector() {
throws BeansException { return new DuplicateServerPropertiesDetector();
this.applicationContext = applicationContext;
} }
@Override /**
public void customize(ConfigurableEmbeddedServletContainer container) { * {@link EmbeddedServletContainerCustomizer} that ensures there is exactly one
// ServerProperties handles customization, this just checks we only have * {@link ServerProperties} bean in the application context.
// a single bean */
String[] serverPropertiesBeans = this.applicationContext private static class DuplicateServerPropertiesDetector implements
.getBeanNamesForType(ServerProperties.class); EmbeddedServletContainerCustomizer, Ordered, ApplicationContextAware {
Assert.state(
serverPropertiesBeans.length == 1, private ApplicationContext applicationContext;
"Multiple ServerProperties beans registered "
+ StringUtils.arrayToCommaDelimitedString(serverPropertiesBeans)); @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));
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment