From e57579461ae5f8bbdd55fe9089c9ba31c1dcbe1f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 2 Jul 2019 14:05:49 +0100 Subject: [PATCH] Prevent endpoint's shutdown() method from being a destroy method Closes gh-17407 --- .../ShutdownEndpointAutoConfiguration.java | 2 +- .../ShutdownEndpointAutoConfigurationTests.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) 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 e0ad45c26f..9638d8ff8d 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; @ConditionalOnEnabledEndpoint(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 37c53b77e4..427aa5e5ce 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.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,9 +39,15 @@ public class ShutdownEndpointAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(ShutdownEndpointAutoConfiguration.class)); @Test - public void runShouldHaveEndpointBean() { - this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true") - .run((context) -> assertThat(context).hasSingleBean(ShutdownEndpoint.class)); + @SuppressWarnings("unchecked") + public void runShouldHaveEndpointBeanThatIsNotDisposable() { + this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true").run((context) -> { + assertThat(context).hasSingleBean(ShutdownEndpoint.class); + ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); + Map disposableBeans = (Map) ReflectionTestUtils.getField(beanFactory, + "disposableBeans"); + assertThat(disposableBeans).isEmpty(); + }); } @Test