mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Merge branch '2.3.x'
Closes gh-22019
This commit is contained in:
commit
c37fd865c0
@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.context;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -36,7 +37,8 @@ import org.springframework.context.support.DefaultLifecycleProcessor;
|
||||
public class LifecycleAutoConfiguration {
|
||||
|
||||
@Bean(name = AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME)
|
||||
@ConditionalOnMissingBean(name = AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME)
|
||||
@ConditionalOnMissingBean(name = AbstractApplicationContext.LIFECYCLE_PROCESSOR_BEAN_NAME,
|
||||
search = SearchStrategy.CURRENT)
|
||||
public DefaultLifecycleProcessor defaultLifecycleProcessor(LifecycleProperties properties) {
|
||||
DefaultLifecycleProcessor lifecycleProcessor = new DefaultLifecycleProcessor();
|
||||
lifecycleProcessor.setTimeoutPerShutdownPhase(properties.getTimeoutPerShutdownPhase().toMillis());
|
||||
|
@ -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) -> {
|
||||
|
Loading…
Reference in New Issue
Block a user