mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Don't consider sources as Initializer or Listener
Update SpringApplication so that source objects are no longer considered as ApplicationListeners or ApplicationContextInitializer.
This commit is contained in:
parent
5e2cfe1cfe
commit
f6a341e79f
@ -304,9 +304,6 @@ public class SpringApplication {
|
||||
|
||||
ApplicationEventMulticaster multicaster = createApplicationEventMulticaster();
|
||||
try {
|
||||
Set<Object> 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<Object> 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<Object> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user