Skip to content

Commit 1e97ff8

Browse files
committed
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
1 parent 28643e4 commit 1e97ff8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/LifecycleAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2020
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
21+
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
2122
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2223
import org.springframework.context.annotation.Bean;
2324
import org.springframework.context.annotation.Configuration;
@@ -36,7 +37,8 @@
3637
public class LifecycleAutoConfiguration {
3738

3839
@Bean(name = AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME)
39-
@ConditionalOnMissingBean(name = AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME)
40+
@ConditionalOnMissingBean(name = AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME,
41+
search = SearchStrategy.CURRENT)
4042
public DefaultLifecycleProcessor defaultLifecycleProcessor(LifecycleProperties properties) {
4143
DefaultLifecycleProcessor lifecycleProcessor = new DefaultLifecycleProcessor();
4244
lifecycleProcessor.setTimeoutPerShutdownPhase(properties.getTimeoutPerShutdownPhase().toMillis());

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/LifecycleAutoConfigurationTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ void lifecycleProcessorIsConfiguredWithCustomDefaultTimeout() {
5555
});
5656
}
5757

58+
@Test
59+
void lifecycleProcessorIsConfiguredWithCustomDefaultTimeoutInAChildContext() {
60+
new ApplicationContextRunner().run((parent) -> {
61+
this.contextRunner.withParent(parent).withPropertyValues("spring.lifecycle.timeout-per-shutdown-phase=15s")
62+
.run((child) -> {
63+
assertThat(child).hasBean(AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME);
64+
Object processor = child.getBean(AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME);
65+
assertThat(processor).extracting("timeoutPerShutdownPhase").isEqualTo(15000L);
66+
});
67+
});
68+
}
69+
5870
@Test
5971
void whenUserDefinesALifecycleProcessorBeanThenTheAutoConfigurationBacksOff() {
6072
this.contextRunner.withUserConfiguration(LifecycleProcessorConfiguration.class).run((context) -> {

0 commit comments

Comments
 (0)