几个重要的事件回调机制
配置在META-INF/spring.factories
ApplicationContextInitializer
SpringApplicationRunListener
只需要放在ioc容器中
ApplicationRunner
**CommandLineRunner**
启动流程:
1、创建SpringApplication对象
initialize(sources);
private void initialize(Object[] sources) { //保存主配置类
if (sources != null && sources.length > 0) {
this.sources.addAll(Arrays.asList(sources));
}
//判断当前是否一个web应用
this.webEnvironment = deduceWebEnvironment();
//从类路径下找到META-INF/spring.factories配置的所有ApplicationContextInitializer;然后保存起来
setInitializers((Collection) getSpringFactoriesInstances(
ApplicationContextInitializer.class));
//从类路径下找到ETA-INF/spring.factories配置的所有ApplicationListener
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
//从多个配置类中找到有main方法的主配置类
this.mainApplicationClass = deduceMainApplicationClass();
}
//判断当前是否一个web应用
//从类路径下找到META-INF/spring.factories配置的所有ApplicationContextInitializer;然后保存起来
//从类路径下找到ETA-INF/spring.factories配置的所有ApplicationListener
//从多个配置类中找到有main方法的主配置类