Prevent endpoint's shutdown() method from being a destroy method
Closes gh-17407
This commit is contained in:
parent
5997886897
commit
e57579461a
|
@ -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();
|
||||
|
|
|
@ -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<String, Object> disposableBeans = (Map<String, Object>) ReflectionTestUtils.getField(beanFactory,
|
||||
"disposableBeans");
|
||||
assertThat(disposableBeans).isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue