Browse Source

Publish ApplicationPreparedEvent before AOT processing abandons run

pull/32488/head
Andy Wilkinson 3 years ago
parent
commit
26eff5ae7a
  1. 2
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
  2. 8
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

2
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

@ -456,7 +456,7 @@ public class SpringApplication { @@ -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);
}

8
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

@ -1302,8 +1302,11 @@ class SpringApplicationTests { @@ -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 { @@ -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

Loading…
Cancel
Save