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();
|
ApplicationEventMulticaster multicaster = createApplicationEventMulticaster();
|
||||||
try {
|
try {
|
||||||
Set<Object> sources = getSources();
|
|
||||||
registerListenerAndInitializerSources(multicaster, sources);
|
|
||||||
|
|
||||||
// Allow logging and stuff to initialize very early
|
// Allow logging and stuff to initialize very early
|
||||||
multicaster.multicastEvent(new ApplicationStartedEvent(this, args));
|
multicaster.multicastEvent(new ApplicationStartedEvent(this, args));
|
||||||
|
|
||||||
|
|
@ -319,17 +316,14 @@ public class SpringApplication {
|
||||||
multicaster.multicastEvent(new ApplicationEnvironmentPreparedEvent(this,
|
multicaster.multicastEvent(new ApplicationEnvironmentPreparedEvent(this,
|
||||||
args, environment));
|
args, environment));
|
||||||
|
|
||||||
// Sources might have changed when environment was applied
|
// Load the sources (might have changed when environment was applied)
|
||||||
sources = getSources();
|
Set<Object> sources = getSources();
|
||||||
Assert.notEmpty(sources, "Sources must not be empty");
|
Assert.notEmpty(sources, "Sources must not be empty");
|
||||||
|
|
||||||
if (this.showBanner) {
|
if (this.showBanner) {
|
||||||
printBanner();
|
printBanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some sources might be listeners
|
|
||||||
registerListenerAndInitializerSources(multicaster, sources);
|
|
||||||
|
|
||||||
// Create, load, refresh and run the ApplicationContext
|
// Create, load, refresh and run the ApplicationContext
|
||||||
context = createApplicationContext();
|
context = createApplicationContext();
|
||||||
registerApplicationEventMulticaster(context, multicaster);
|
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(
|
private void registerApplicationEventMulticaster(
|
||||||
ConfigurableApplicationContext context,
|
ConfigurableApplicationContext context,
|
||||||
ApplicationEventMulticaster multicaster) {
|
ApplicationEventMulticaster multicaster) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue