diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java index 3510b03267..79f345aa61 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java @@ -33,7 +33,7 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnAvailableEndpoint(endpoint = ShutdownEndpoint.class) public class ShutdownEndpointAutoConfiguration { - @Bean + @Bean(destroyMethod = "") @ConditionalOnMissingBean public ShutdownEndpoint shutdownEndpoint() { return new ShutdownEndpoint(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfigurationTests.java index 166455e77e..4435c173d9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfigurationTests.java @@ -16,11 +16,15 @@ package org.springframework.boot.actuate.autoconfigure.context; +import java.util.Map; + import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.actuate.context.ShutdownEndpoint; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -35,10 +39,15 @@ class ShutdownEndpointAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(ShutdownEndpointAutoConfiguration.class)); @Test - void runShouldHaveEndpointBean() { + void runShouldHaveEndpointBeanThatIsNotDisposable() { this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true") - .withPropertyValues("management.endpoints.web.exposure.include=shutdown") - .run((context) -> assertThat(context).hasSingleBean(ShutdownEndpoint.class)); + .withPropertyValues("management.endpoints.web.exposure.include=shutdown").run((context) -> { + assertThat(context).hasSingleBean(ShutdownEndpoint.class); + ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); + Map disposableBeans = (Map) ReflectionTestUtils + .getField(beanFactory, "disposableBeans"); + assertThat(disposableBeans).isEmpty(); + }); } @Test