SpringApplication.run做了哪些事?
* Class that can be used to bootstrap and launch a Spring application from a Java main method. By default class will perform the following steps to bootstrap your application:
* Create an appropriate {[@link](https://my.oschina.net/u/393) ApplicationContext} instance (depending on your classpath)
* Register a {[@link](https://my.oschina.net/u/393) CommandLinePropertySource} to expose command line arguments as Spring properties
* Refresh the application context, loading all singleton beans
* Trigger any {[@link](https://my.oschina.net/u/393) CommandLineRunner} beans
译文:
是一个可以从main函数中引导和加载Spring应用程序。默认地,class将执行以下步骤:
1.从类路径中创建一个恰当的ApplicationContext实例(应用上下文实例);
2.注册一个CommandLinePropertySource,用于暴露命令行参数作为Spring的属性;
3.唤醒应用上下文,加载所有的单例beans;
4.触发所有的CommandLineRunner beans
网友答案:
SpringApplication.run一共做了两件事,一件是创建SpringApplication对象,在该对象初始化时,找到配置的事件监听器,并保存起来.第二件事就是运行run方法,此时会将刚才保存的事件监听器根据当前时机触发不同的事件,比如容器初始化,容器创建完成等.同时也会刷新IoC容器,进行组件的扫描、创建、加载等工作.这两件事我都看过源码,我分别给你画个图细致讲一讲.