Commit aeef41c9 authored by Brian Clozel's avatar Brian Clozel

Separate container customization from ServerProperties

This commit creates a separate
`ServerPropertiesServletContainerCustomizer` that holds the servlet
container customization code, separating that concern from the server
configuration keys.

See gh-8066
parent 8899b93d
......@@ -40,6 +40,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.hateoas.HypermediaHttpMessageConverterConfiguration;
import org.springframework.boot.autoconfigure.web.DefaultServletContainerCustomizer;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ServerProperties;
......@@ -182,6 +183,8 @@ public class EndpointWebMvcChildContextConfiguration {
private ServerProperties server;
private DefaultServletContainerCustomizer serverCustomizer;
@Override
public int getOrder() {
return 0;
......@@ -195,10 +198,12 @@ public class EndpointWebMvcChildContextConfiguration {
ManagementServerProperties.class);
this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors(
this.beanFactory, ServerProperties.class);
this.serverCustomizer = BeanFactoryUtils.beanOfTypeIncludingAncestors(
this.beanFactory, DefaultServletContainerCustomizer.class);
}
// Customize as per the parent context first (so e.g. the access logs go to
// the same place)
this.server.customize(container);
this.serverCustomizer.customize(container);
// Then reset the error pages
container.setErrorPages(Collections.<ErrorPage>emptySet());
// and the context path
......
......@@ -736,7 +736,7 @@ public class EndpointWebMvcAutoConfigurationTests {
}
@Configuration
@Import({ PropertyPlaceholderAutoConfiguration.class,
@Import({PropertyPlaceholderAutoConfiguration.class,
EmbeddedServletContainerAutoConfiguration.class,
JacksonAutoConfiguration.class, EndpointAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
......
......@@ -60,6 +60,7 @@ import org.springframework.util.ObjectUtils;
* @author Phillip Webb
* @author Dave Syer
* @author Ivan Sopov
* @author Brian Clozel
*/
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@Configuration
......@@ -68,6 +69,13 @@ import org.springframework.util.ObjectUtils;
@Import(BeanPostProcessorsRegistrar.class)
public class EmbeddedServletContainerAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public DefaultServletContainerCustomizer serverPropertiesServletContainerCustomizer(
ServerProperties serverProperties) {
return new DefaultServletContainerCustomizer(serverProperties);
}
/**
* Nested configuration if Tomcat is being used.
*/
......
......@@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"spring.jersey.type=filter", "server.servlet.contextPath=/app" })
"spring.jersey.type=filter", "server.servlet.context-path=/app" })
@DirtiesContext
public class JerseyAutoConfigurationCustomFilterContextPathTests {
......
......@@ -44,12 +44,12 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Integration tests for {@link ServerProperties}.
* Integration tests for {@link DefaultServletContainerCustomizer}.
*
* @author Dave Syer
* @author Ivan Sopov
*/
public class ServerPropertiesIntegrationTests {
public class DefaultServletContainerCustomizerIntegrationTests {
private static AbstractEmbeddedServletContainerFactory containerFactory;
......@@ -142,9 +142,14 @@ public class ServerPropertiesIntegrationTests {
@EnableConfigurationProperties(ServerProperties.class)
protected static class Config {
@Bean
public DefaultServletContainerCustomizer defaultServletContainerCustomizer(ServerProperties properties) {
return new DefaultServletContainerCustomizer(properties);
}
@Bean
public EmbeddedServletContainerFactory containerFactory() {
return ServerPropertiesIntegrationTests.containerFactory;
return DefaultServletContainerCustomizerIntegrationTests.containerFactory;
}
@Bean
......
......@@ -122,8 +122,8 @@ public class EmbeddedServletContainerAutoConfigurationTests {
public void initParametersAreConfiguredOnTheServletContext() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"server.servlet.context_parameters.a:alpha",
"server.servlet.context_parameters.b:bravo");
"server.servlet.context-parameters.a:alpha",
"server.servlet.context-parameters.b:bravo");
this.context.register(BaseConfiguration.class);
this.context.refresh();
......
......@@ -35,10 +35,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.devtools.classpath.ClassPathChangedEvent;
import org.springframework.boot.devtools.classpath.ClassPathFileSystemWatcher;
import org.springframework.boot.devtools.filewatch.ChangedFiles;
......@@ -281,7 +279,6 @@ public class LocalDevToolsAutoConfigurationTests {
@Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class,
LocalDevToolsAutoConfiguration.class, ThymeleafAutoConfiguration.class })
@EnableConfigurationProperties(ServerProperties.class)
public static class Config {
}
......@@ -289,7 +286,6 @@ public class LocalDevToolsAutoConfigurationTests {
@Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class,
LocalDevToolsAutoConfiguration.class, ThymeleafAutoConfiguration.class })
@EnableConfigurationProperties(ServerProperties.class)
public static class ConfigWithMockLiveReload {
@Bean
......@@ -302,7 +298,6 @@ public class LocalDevToolsAutoConfigurationTests {
@Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class,
LocalDevToolsAutoConfiguration.class, ResourceProperties.class })
@EnableConfigurationProperties(ServerProperties.class)
public static class WebResourcesConfig {
}
......
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