From e9eae2cc1e8c0a0ba0eaada94bc67dcf4e6c3930 Mon Sep 17 00:00:00 2001 From: Jean de Klerk Date: Sat, 5 Dec 2015 21:20:06 -0700 Subject: [PATCH] Log exception before sending to listeners Change SpringApplication exception handling to log details before calling the SpringApplicationRunListeners. Prior to this commit it wasn't possible for a listener to shutdown logging. Fixes gh-4680 Closes gh-4686 --- .../java/org/springframework/boot/SpringApplication.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 4a7b705056..2e92f6541a 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -819,6 +819,10 @@ public class SpringApplication { private void handleRunFailure(ConfigurableApplicationContext context, SpringApplicationRunListeners listeners, Throwable exception) { + if (this.log.isErrorEnabled()) { + this.log.error("Application startup failed", exception); + registerLoggedException(exception); + } try { try { listeners.finished(context, exception); @@ -832,10 +836,6 @@ public class SpringApplication { catch (Exception ex) { this.log.warn("Unable to close ApplicationContext", ex); } - if (this.log.isErrorEnabled()) { - this.log.error("Application startup failed", exception); - registerLoggedException(exception); - } ReflectionUtils.rethrowRuntimeException(exception); }