diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java index 1b86940cc9..9024aa7027 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java @@ -42,6 +42,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; @@ -87,6 +88,7 @@ import org.springframework.web.servlet.DispatcherServlet; * @author Christian Dupuis * @author Andy Wilkinson * @author Johannes Edmeier + * @author Eddú Meléndez */ @Configuration @ConditionalOnClass({ Servlet.class, DispatcherServlet.class }) @@ -198,6 +200,7 @@ public class EndpointWebMvcAutoConfiguration // Put Servlets and Filters in their own nested class so they don't force early // instantiation of ManagementServerProperties. @Configuration + @ConditionalOnProperty(prefix = "management", name = "addApplicationContextHeader", matchIfMissing = true, havingValue = "true") protected static class ApplicationContextFilterConfiguration { @Bean 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 b99db580a9..f920953f4e 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 @@ -98,6 +98,7 @@ import static org.mockito.Mockito.mock; * @author Phillip Webb * @author Greg Turnquist * @author Andy Wilkinson + * @author Eddú Meléndez */ public class EndpointWebMvcAutoConfigurationTests { @@ -136,6 +137,7 @@ public class EndpointWebMvcAutoConfigurationTests { assertContent("/controller", ports.get().management, null); assertContent("/endpoint", ports.get().management, null); assertTrue(hasHeader("/endpoint", ports.get().server, "X-Application-Context")); + assertTrue(this.applicationContext.containsBean("applicationContextIdFilter")); this.applicationContext.close(); assertAllClosed(); } @@ -149,6 +151,7 @@ public class EndpointWebMvcAutoConfigurationTests { EndpointWebMvcAutoConfiguration.class); this.applicationContext.refresh(); assertFalse(hasHeader("/endpoint", ports.get().server, "X-Application-Context")); + assertFalse(this.applicationContext.containsBean("applicationContextIdFilter")); this.applicationContext.close(); assertAllClosed(); }