@@ -299,7 +299,6 @@ public ConfigurableApplicationContext run(String... args) {
299
299
StopWatch stopWatch = new StopWatch ();
300
300
stopWatch .start ();
301
301
ConfigurableApplicationContext context = null ;
302
- Collection <SpringBootExceptionReporter > exceptionReporters = new ArrayList <>();
303
302
configureHeadlessProperty ();
304
303
SpringApplicationRunListeners listeners = getRunListeners (args );
305
304
listeners .starting ();
@@ -309,8 +308,6 @@ public ConfigurableApplicationContext run(String... args) {
309
308
configureIgnoreBeanInfo (environment );
310
309
Banner printedBanner = printBanner (environment );
311
310
context = createApplicationContext ();
312
- exceptionReporters = getSpringFactoriesInstances (SpringBootExceptionReporter .class ,
313
- new Class [] { ConfigurableApplicationContext .class }, context );
314
311
prepareContext (context , environment , listeners , applicationArguments , printedBanner );
315
312
refreshContext (context );
316
313
afterRefresh (context , applicationArguments );
@@ -322,15 +319,15 @@ public ConfigurableApplicationContext run(String... args) {
322
319
callRunners (context , applicationArguments );
323
320
}
324
321
catch (Throwable ex ) {
325
- handleRunFailure (context , ex , exceptionReporters , listeners );
322
+ handleRunFailure (context , ex , listeners );
326
323
throw new IllegalStateException (ex );
327
324
}
328
325
329
326
try {
330
327
listeners .running (context );
331
328
}
332
329
catch (Throwable ex ) {
333
- handleRunFailure (context , ex , exceptionReporters , null );
330
+ handleRunFailure (context , ex , null );
334
331
throw new IllegalStateException (ex );
335
332
}
336
333
return context ;
@@ -800,7 +797,7 @@ private void callRunner(CommandLineRunner runner, ApplicationArguments args) {
800
797
}
801
798
802
799
private void handleRunFailure (ConfigurableApplicationContext context , Throwable exception ,
803
- Collection < SpringBootExceptionReporter > exceptionReporters , SpringApplicationRunListeners listeners ) {
800
+ SpringApplicationRunListeners listeners ) {
804
801
try {
805
802
try {
806
803
handleExitCode (context , exception );
@@ -809,7 +806,7 @@ private void handleRunFailure(ConfigurableApplicationContext context, Throwable
809
806
}
810
807
}
811
808
finally {
812
- reportFailure (exceptionReporters , exception );
809
+ reportFailure (context , exception );
813
810
if (context != null ) {
814
811
context .close ();
815
812
}
@@ -821,9 +818,9 @@ private void handleRunFailure(ConfigurableApplicationContext context, Throwable
821
818
ReflectionUtils .rethrowRuntimeException (exception );
822
819
}
823
820
824
- private void reportFailure (Collection < SpringBootExceptionReporter > exceptionReporters , Throwable failure ) {
821
+ private void reportFailure (ApplicationContext context , Throwable failure ) {
825
822
try {
826
- for (SpringBootExceptionReporter reporter : exceptionReporters ) {
823
+ for (SpringBootExceptionReporter reporter : getExceptionReporters ( context ) ) {
827
824
if (reporter .reportException (failure )) {
828
825
registerLoggedException (failure );
829
826
return ;
@@ -839,6 +836,19 @@ private void reportFailure(Collection<SpringBootExceptionReporter> exceptionRepo
839
836
}
840
837
}
841
838
839
+ private Collection <SpringBootExceptionReporter > getExceptionReporters (ApplicationContext context ) {
840
+ try {
841
+ if (context != null ) {
842
+ return getSpringFactoriesInstances (SpringBootExceptionReporter .class ,
843
+ new Class [] { ConfigurableApplicationContext .class }, context );
844
+ }
845
+ }
846
+ catch (Throwable ex ) {
847
+ // Continue
848
+ }
849
+ return Collections .emptyList ();
850
+ }
851
+
842
852
/**
843
853
* Register that the given exception has been logged. By default, if the running in
844
854
* the main thread, this method will suppress additional printing of the stacktrace.
0 commit comments