Closed as not planned
Closed as not planned
Description
When closing the applicationContext, those Lifecycle
beans are stopped earlier than normal beans.
// AbstractApplicationContext.doClose
protected void doClose() {
publishEvent(new ContextClosedEvent(this));
if (this.lifecycleProcessor != null) {
try {
this.lifecycleProcessor.onClose();
}catch (Throwable ex) {}
}
destroyBeans();
closeBeanFactory();
onClose();
resetCommonCaches();
}
And the default lifecycle processor only close those beans which are Lifecycle
// DefaultLifecycleProcessor
private void doStop(Map<String, ? extends Lifecycle> lifecycleBeans, final String beanName,
final CountDownLatch latch, final Set<String> countDownBeanNames) {
Lifecycle bean = lifecycleBeans.remove(beanName);
if (bean != null) {
String[] dependentBeans = getBeanFactory().getDependentBeans(beanName);
for (String dependentBean : dependentBeans) {
// so if the dependentBean is not LifeCycle type, it will be skipped to stop
doStop(lifecycleBeans, dependentBean, latch, countDownBeanNames);
}
// codes which are doing the cleanup
// ...
}
}
If normal beans which depend on Lifecycle
beans may not work properly during the closing period, because their depending Lifecycle
beans are stopped earlier.