diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 3f57ae7568..569592937e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -456,7 +456,7 @@ public class SpringApplication { SpringApplicationRunListener hookListener = (hook != null) ? hook.getRunListener(this) : null; if (hookListener != null) { listeners = new ArrayList<>(listeners); - listeners.add(0, hookListener); + listeners.add(hookListener); } return new SpringApplicationRunListeners(logger, listeners, this.applicationStartup); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 70e4727641..575519b8d0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -1302,8 +1302,11 @@ class SpringApplicationTests { } @Test + @SuppressWarnings({ "rawtypes", "unchecked" }) void withHookWhenHookThrowsAbandonedRunExceptionAbandonsRun() { SpringApplication application = new SpringApplication(ExampleConfig.class); + ApplicationListener listener = mock(ApplicationListener.class); + application.addListeners(listener); application.setWebApplicationType(WebApplicationType.NONE); SpringApplicationRunListener runListener = spy(new SpringApplicationRunListener() { @@ -1321,6 +1324,11 @@ class SpringApplicationTests { then(runListener).should().contextPrepared(any()); then(runListener).should(never()).ready(any(), any()); then(runListener).should(never()).failed(any(), any()); + then(listener).should().onApplicationEvent(any(ApplicationStartingEvent.class)); + then(listener).should().onApplicationEvent(any(ApplicationEnvironmentPreparedEvent.class)); + then(listener).should().onApplicationEvent(any(ApplicationPreparedEvent.class)); + then(listener).should(never()).onApplicationEvent(any(ApplicationReadyEvent.class)); + then(listener).should(never()).onApplicationEvent(any(ApplicationFailedEvent.class)); } @Test