diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java index fefe79cb1a..9f439939fe 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java @@ -39,7 +39,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; @@ -67,7 +66,6 @@ import org.springframework.util.StringUtils; */ @ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false) @ConditionalOnWebApplication(type = Type.SERVLET) -@EnableConfigurationProperties(ManagementServerProperties.class) class ServletManagementChildContextConfiguration { @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java index 7bfbd7153a..10cdda011b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java @@ -19,6 +19,8 @@ package org.springframework.boot.actuate.autoconfigure.web.reactive; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.autoconfigure.web.reactive.ReactiveManagementChildContextConfiguration.AccessLogCustomizer; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -46,4 +48,24 @@ class ReactiveManagementChildContextConfigurationTests { assertThat(customizer.customizePrefix("existing")).isEqualTo("existing"); } + @Test + // gh-45857 + void failsWithoutManagementServerPropertiesBeanFromParent() { + new ReactiveWebApplicationContextRunner().run((parent) -> { + new ReactiveWebApplicationContextRunner().withParent(parent) + .withUserConfiguration(ReactiveManagementChildContextConfiguration.class) + .run((context) -> assertThat(context).hasFailed()); + }); + } + + @Test + // gh-45857 + void succeedsWithManagementServerPropertiesBeanFromParent() { + new ReactiveWebApplicationContextRunner().withBean(ManagementServerProperties.class).run((parent) -> { + new ReactiveWebApplicationContextRunner().withParent(parent) + .withUserConfiguration(ReactiveManagementChildContextConfiguration.class) + .run((context) -> assertThat(context).hasNotFailed()); + }); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java index a46dca62ca..e4c3e3d051 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java @@ -18,7 +18,9 @@ package org.springframework.boot.actuate.autoconfigure.web.servlet; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementChildContextConfiguration.AccessLogCustomizer; +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -46,4 +48,24 @@ class ServletManagementChildContextConfigurationTests { assertThat(customizer.customizePrefix("existing")).isEqualTo("existing"); } + @Test + // gh-45857 + void failsWithoutManagementServerPropertiesBeanFromParent() { + new WebApplicationContextRunner().run((parent) -> { + new WebApplicationContextRunner().withParent(parent) + .withUserConfiguration(ServletManagementChildContextConfiguration.class) + .run((context) -> assertThat(context).hasFailed()); + }); + } + + @Test + // gh-45857 + void succeedsWithManagementServerPropertiesBeanFromParent() { + new WebApplicationContextRunner().withBean(ManagementServerProperties.class).run((parent) -> { + new WebApplicationContextRunner().withParent(parent) + .withUserConfiguration(ServletManagementChildContextConfiguration.class) + .run((context) -> assertThat(context).hasNotFailed()); + }); + } + }