Springboot 启动流程
Springboot 启动流程
- 构建SpringApplicaiton对象
- 执行SpringApplicaiton.run()
构建SpringApplicaiton对象
-
通过loadClass的方式,推测webApplicationType。比如,如果可以加载到javax.servlet.Servlet类,那么就是Servlet应用类型。
-
从spring.factories中加载initializers和listeners
ApplicationRunListener: 在启动过程中的各个节点发布不同的事件,可以实现该接口,在不同节点打印信息 -
推测出main方法所在的类
执行SpringApplicaiton.run()
- 获取SpringApplicationRunListeners
- RunListener步骤标记:spring.boot.application.starting
- 根据webApplicationType生成Environemnt对象
- 读取args(命令行参数SimpleCommandLinePropertySource)、JVM参数(systemProperties)、操作系统参数(systemEnvironment)放入environment中,读取配置文件application.xml或用户指定路径的配置文件?
- 步骤标记:spring.boot.application.environment-prepared
- 打印banner
- 创建applicationContext,把environment设置到applicationContext中
- 调用initializers的initialize方法
- 步骤标记:spring.boot.application.context-prepared
- 设置一些singleton和参数如是否允许循环依赖,是否允许beanDefinition覆盖等
- 步骤标记:spring.boot.application.context-loaded
- Spring的容器refresh
- 步骤标记:spring.boot.application.started
- 调用Runner(ApplicationRunner、CommandLineRunner)的run方法(扩展点)
- 步骤标记:spring.boot.application.ready