Commit 8628adcb authored by Phillip Webb's avatar Phillip Webb

Order EmbeddedServletContainerCustomizers

Add Ordered interface to all EmbeddedServletContainerCustomizers with
a value of 0. Prior to this commit it was difficult for a user to
define a customizer that would be applied before ours, even if they
implemented Ordered or added @Order annotations.

Fixes gh-2123
parent ef621c92
......@@ -50,6 +50,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomi
import org.springframework.boot.context.embedded.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.servlet.DispatcherServlet;
......@@ -79,7 +80,7 @@ public class EndpointWebMvcChildContextConfiguration {
@Configuration
protected static class ServerCustomization implements
EmbeddedServletContainerCustomizer {
EmbeddedServletContainerCustomizer, Ordered {
@Value("${error.path:/error}")
private String errorPath = "/error";
......@@ -93,6 +94,11 @@ public class EndpointWebMvcChildContextConfiguration {
private ServerProperties server;
@Override
public int getOrder() {
return 0;
}
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (this.managementServerProperties == null) {
......
......@@ -70,7 +70,8 @@ import org.springframework.web.util.HtmlUtils;
// available
@AutoConfigureBefore(WebMvcAutoConfiguration.class)
@Configuration
public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustomizer {
public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustomizer,
Ordered {
@Value("${error.path:/error}")
private String errorPath = "/error";
......@@ -78,6 +79,11 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
@Autowired
private ServerProperties properties;
@Override
public int getOrder() {
return 0;
}
@Bean
@ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
public DefaultErrorAttributes errorAttributes() {
......
......@@ -43,6 +43,7 @@ import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletCon
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.Ordered;
import org.springframework.util.StringUtils;
/**
......@@ -56,7 +57,7 @@ import org.springframework.util.StringUtils;
* @author Ivan Sopov
*/
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = false)
public class ServerProperties implements EmbeddedServletContainerCustomizer {
public class ServerProperties implements EmbeddedServletContainerCustomizer, Ordered {
/**
* Server HTTP port.
......@@ -96,6 +97,11 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
*/
private final Map<String, String> contextParameters = new HashMap<String, String>();
@Override
public int getOrder() {
return 0;
}
public Tomcat getTomcat() {
return this.tomcat;
}
......
......@@ -28,6 +28,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
......@@ -41,10 +42,15 @@ import org.springframework.util.StringUtils;
@EnableConfigurationProperties
@ConditionalOnWebApplication
public class ServerPropertiesAutoConfiguration implements ApplicationContextAware,
EmbeddedServletContainerCustomizer {
EmbeddedServletContainerCustomizer, Ordered {
private ApplicationContext applicationContext;
@Override
public int getOrder() {
return 0;
}
@Bean
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
public ServerProperties serverProperties() {
......
......@@ -22,6 +22,7 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.web.NonEmbeddedServletContainerFactory;
import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
/**
......@@ -34,10 +35,15 @@ import org.springframework.core.ResolvableType;
* @since 1.2.0
*/
public abstract class WebSocketContainerCustomizer<T extends EmbeddedServletContainerFactory>
implements EmbeddedServletContainerCustomizer {
implements EmbeddedServletContainerCustomizer, Ordered {
private Log logger = LogFactory.getLog(getClass());
@Override
public int getOrder() {
return 0;
}
@SuppressWarnings("unchecked")
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
......
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