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 e5f8eab4a3f..965b5ed7487 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -304,9 +304,6 @@ public class SpringApplication { ApplicationEventMulticaster multicaster = createApplicationEventMulticaster(); try { - Set sources = getSources(); - registerListenerAndInitializerSources(multicaster, sources); - // Allow logging and stuff to initialize very early multicaster.multicastEvent(new ApplicationStartedEvent(this, args)); @@ -319,17 +316,14 @@ public class SpringApplication { multicaster.multicastEvent(new ApplicationEnvironmentPreparedEvent(this, args, environment)); - // Sources might have changed when environment was applied - sources = getSources(); + // Load the sources (might have changed when environment was applied) + Set sources = getSources(); Assert.notEmpty(sources, "Sources must not be empty"); if (this.showBanner) { printBanner(); } - // Some sources might be listeners - registerListenerAndInitializerSources(multicaster, sources); - // Create, load, refresh and run the ApplicationContext context = createApplicationContext(); registerApplicationEventMulticaster(context, multicaster); @@ -391,18 +385,6 @@ public class SpringApplication { } } - private void registerListenerAndInitializerSources( - ApplicationEventMulticaster multicaster, Set sources) { - for (Object object : sources) { - if (object instanceof ApplicationListener) { - multicaster.addApplicationListener((ApplicationListener) object); - } - if (object instanceof ApplicationContextInitializer) { - addInitializers((ApplicationContextInitializer) object); - } - } - } - private void registerApplicationEventMulticaster( ConfigurableApplicationContext context, ApplicationEventMulticaster multicaster) {