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