Ensure SpringApplication closes its ApplicationContext
...even if the CommandLineRunners fail and we drop to the error handling path. Fixes gh-211
This commit is contained in:
@@ -360,18 +360,25 @@ public class SpringApplication {
|
||||
return context;
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context,
|
||||
args, ex));
|
||||
handleError(context, multicaster, ex, args);
|
||||
throw ex;
|
||||
}
|
||||
catch (Error ex) {
|
||||
multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context,
|
||||
args, ex));
|
||||
handleError(context, multicaster, ex, args);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void handleError(ConfigurableApplicationContext context,
|
||||
ApplicationEventMulticaster multicaster, Throwable ex, String... args) {
|
||||
multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context, args,
|
||||
ex));
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListeners(ApplicationEventMulticaster multicaster,
|
||||
Set<Object> sources) {
|
||||
for (Object object : sources) {
|
||||
|
||||
Reference in New Issue
Block a user