Commit c349cb66 authored by Dave Syer's avatar Dave Syer

Ensure SpringApplication closes its ApplicationContext

...even if the CommandLineRunners fail and we drop to the error
handling path.

Fixes gh-211
parent 420fc699
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment