mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Stop already started Lifecycle beans on cancelled refresh
Closes gh-35964
This commit is contained in:
+11
-1
@@ -623,12 +623,22 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||
finishRefresh();
|
||||
}
|
||||
|
||||
catch (RuntimeException | Error ex ) {
|
||||
catch (RuntimeException | Error ex) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Exception encountered during context initialization - " +
|
||||
"cancelling refresh attempt: " + ex);
|
||||
}
|
||||
|
||||
// Stop already started Lifecycle beans to avoid dangling resources.
|
||||
if (this.lifecycleProcessor != null && this.lifecycleProcessor.isRunning()) {
|
||||
try {
|
||||
this.lifecycleProcessor.stop();
|
||||
}
|
||||
catch (Throwable ex2) {
|
||||
logger.warn("Exception thrown from LifecycleProcessor on cancelled refresh", ex2);
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy already created singletons to avoid dangling resources.
|
||||
destroyBeans();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user