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;
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;
}
}
}
/*
* 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,12 +37,30 @@ 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 {
public class ServerPropertiesAutoConfiguration {
@Bean
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
public ServerProperties serverProperties() {
return new ServerProperties();
}
@Bean
public DuplicateServerPropertiesDetector duplicateServerPropertiesDetector() {
return new DuplicateServerPropertiesDetector();
}
/**
* {@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;
......@@ -51,12 +69,6 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar
return 0;
}
@Bean
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
public ServerProperties serverProperties() {
return new ServerProperties();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
......@@ -72,7 +84,10 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar
Assert.state(
serverPropertiesBeans.length == 1,
"Multiple ServerProperties beans registered "
+ StringUtils.arrayToCommaDelimitedString(serverPropertiesBeans));
+ 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