diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java index c15421aa15c..35db5b38637 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -36,6 +37,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.autoconfigure.web.ErrorAttributes; import org.springframework.boot.autoconfigure.web.HttpMessageConverters; +import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; @@ -75,13 +77,23 @@ public class EndpointWebMvcChildContextConfiguration { // instances get their callback very early in the context lifecycle. private ManagementServerProperties managementServerProperties; + private ServerProperties server; + @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (this.managementServerProperties == null) { this.managementServerProperties = BeanFactoryUtils .beanOfTypeIncludingAncestors(this.beanFactory, ManagementServerProperties.class); + this.server = BeanFactoryUtils + .beanOfTypeIncludingAncestors(this.beanFactory, + ServerProperties.class); } + // Customize as per the parent context first (so e.g. the access logs go to the same place) + server.customize(container); + // Then reset the error pages + container.setErrorPages(Collections.emptySet()); + // and add the management-specific bits container.setPort(this.managementServerProperties.getPort()); container.setAddress(this.managementServerProperties.getAddress()); container.setContextPath(this.managementServerProperties.getContextPath()); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index 21218792b82..5c1b4e13a4b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; +import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.test.EnvironmentTestUtils; @@ -222,6 +223,7 @@ public class EndpointWebMvcAutoConfigurationTests { assertThat(localServerPort, notNullValue()); assertThat(localManagementPort, notNullValue()); assertThat(localServerPort, not(equalTo(localManagementPort))); + assertThat(applicationContext.getBean(ServerPortConfig.class).getCount(), equalTo(2)); this.applicationContext.close(); assertAllClosed(); } @@ -303,10 +305,22 @@ public class EndpointWebMvcAutoConfigurationTests { @Configuration public static class ServerPortConfig { + + private int count = 0; + + public int getCount() { + return count; + } @Bean public ServerProperties serverProperties() { - ServerProperties properties = new ServerProperties(); + ServerProperties properties = new ServerProperties() { + @Override + public void customize(ConfigurableEmbeddedServletContainer container) { + count++; + super.customize(container); + } + }; properties.setPort(ports.get().server); return properties; } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties index 49672f79a12..d36c067f877 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties @@ -1,6 +1,7 @@ logging.file: /tmp/logs/app.log logging.level.org.springframework.security: INFO management.address: 127.0.0.1 +#management.port: 8181 endpoints.shutdown.enabled: true server.tomcat.basedir: target/tomcat server.tomcat.access_log_enabled: true