##在spring cloud启动方法中,发现listeners.starting()后,try里的方法环境配置等依次循环执行了多次,事实上是触发了不同事件的onApplicationEvent方法,来看下这些依次怎么个顺序以及发生了什么事
public ConfigurableApplicationContext run(String... args) {
...
SpringApplicationRunListeners listeners = this.getRunListeners(args);
listeners.starting();
Collection exceptionReporters;
try {
ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
ConfigurableEnvironment environment = this.prepareEnvironment(listeners, applicationArguments);
this.configureIgnoreBeanInfo(environment);
...
}
点入断点进入,第一个是
第一个是org.springframework.boot.context.logging.LoggingApplicationListener
查看其事件方法
/**
* 容器启动的时的事件
* @param event
*/
private void onApplicationStartingEvent(ApplicationStartingEvent event) {
// 获得loggingSystem对象
this.loggingSystem = LoggingSystem
.get(event.getSpringApplication().getClassLoader());
// 进行日志初始化
this