Only consider current context when finding lifecycle processor

Previously, LifecycleAutoConfiguration would check the current context
and all of its ancestors for a lifecycle processor bean, only
configuring a custom processor if one was not found. Every context
has a lifecycle processor so this check meant that lifecycle processing
timeout could not be customized in any context with a parent.

This commit updates the auto-configuration to only check the current
context.

Closes gh-22014
This commit is contained in:
Andy Wilkinson
2020-06-19 08:19:57 +01:00
parent 28643e4d2d
commit 1e97ff834e
2 changed files with 15 additions and 1 deletions

View File

@@ -55,6 +55,18 @@ public class LifecycleAutoConfigurationTests {
});
}
@Test
void lifecycleProcessorIsConfiguredWithCustomDefaultTimeoutInAChildContext() {
new ApplicationContextRunner().run((parent) -> {
this.contextRunner.withParent(parent).withPropertyValues("spring.lifecycle.timeout-per-shutdown-phase=15s")
.run((child) -> {
assertThat(child).hasBean(AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME);
Object processor = child.getBean(AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME);
assertThat(processor).extracting("timeoutPerShutdownPhase").isEqualTo(15000L);
});
});
}
@Test
void whenUserDefinesALifecycleProcessorBeanThenTheAutoConfigurationBacksOff() {
this.contextRunner.withUserConfiguration(LifecycleProcessorConfiguration.class).run((context) -> {