[关闭]
@zhuanxu 2017-11-27T12:30:28.000000Z 字数 1185 阅读 1959

spring boot 运行流程分析

spring-boot


运行流程:
1. 判断是否是web环境
判断"javax.servlet.Servlet",
"org.springframework.web.context.ConfigurableWebApplicationContext"
这两个类是否存在
2. 在classpath下面的META-INF/spring.factories文件中,读取ApplicationContextInitializer
3. 在classpath下面的META-INF/spring.factories文件中,读取 ApplicationContextInitializer
4. 推断main方法所在的类
5. 开始执行run方法
6. 设置 java.awt.headless 系统变量
7. 在classpath下面的META-INF/spring.factories文件中,读取 SpringApplicationRunListener
8. 执行所有 SpringApplicationRunListener 的 starting 方法
9. 实例化ApplicationArguments
10. 创建environment
11. 配置environment,主要是把参数配置到 environment
12. 执行所有SpringApplicationRunListener 的 environmentPrepared 方法
13. 如果不是web环境,将environment转化为标准的environment
14. 打印banner
15. 初始化 ConfigurableApplicationContext ,如果是web环境则实例化 AnnotationConfigEmbeddedWebApplicationContext 对象,否则 AnnotationConfigApplicationContext 对象
16. 回调所有的 ApplicationContextInitializerinitialize 方法
17. 执行所有 SpringApplicationRunListener 的 contextPrepared 方法
18. 依次向容器中注入 springApplicationArguments, springBootBanner
19. 加载所有的源到 ConfigurableApplicationContext 中去
20. 执行所有SpringApplicationRunListener 的 contextLoaded 方法
21. 执行 Context 的 refresh 方法,并调用 registerShutdownHook 方法
22. 加载所有的 ApplicationRunner 和 CommandLineRunner ,并一次执行 run 方法
23. 执行所有 SpringApplicationRunListener 的 finished 方法

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注