7_2.springboot2.x启动配置原理_2.运行run方法
当创建完SpringApplication对象之后运行run方法
public ConfigurableApplicationContext run(String... args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
configureHeadlessProperty();
//获取SpringApplicationRunListener;;从类路径下META‐INF/spring.factories获取
SpringApplicationRunListeners listeners = getRunListeners(args);
//回调所有的获取SpringApplicationRunListener.starting()方法
listeners.starting();
try {
//封装命令行参数
ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
//准备环境
ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
//创建环境完成后回调SpringApplicationRunListener.environmentPrepared();表示环境准备完成
configureIgnoreBeanInfo(environment);
//控制台打印图标
Banner printedBanner = printBanner(environment);
//创建ApplicationContext;决定创建web的ioc还是普通的ioc
context = createApplicationContext();
//异常的处理
exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class,
new Class[] { ConfigurableApplicationContext.class }, context);
//准备上下文环境;将environment保存到ioc中;而且applyInitializers();
//applyInitializers():回调之前保存的所有的ApplicationContextInitializer的initialize方法
//回调所有的SpringApplicationRunListener的contextPrepared();
prepareContext(context, environment, listeners, applicationArguments, printedBanner);
//刷新容器;ioc容器初始化(如果是web应用还会创建嵌入式的Tomcat)
//扫描,创建,加载所有组件的地方;(配置类,组件,自动配置)
refreshContext(context);
//从ioc容器中获取所有的ApplicationRunner和CommandLineRunner进行回调
//ApplicationRunner先回调,CommandLineRunner再回调
afterRefresh(context, applicationArguments);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
}
listeners.started(context);
callRunners(context, applicationArguments);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, listeners);
throw new IllegalStateException(ex);
}
try {
listeners.running(context);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, null);
throw new IllegalStateException(ex);
}
//整个SpringBoot应用启动完成以后返回启动的ioc容器;
return context;
}
解析run方法部分代码:
1. prepareContext(context, environment, listeners, applicationArguments, printedBanner);
prepareContext(context, environment, listeners, applicationArguments, printedBanner)
将前面创建的SpringApplication对象中,从类路径下找到META‐INF/spring.factories配置的所有ApplicationContextInitializer的initialize方法
listeners.contextPrepared(context);
回调所有的SpringApplicationRunListener的contextPrepared();
prepareContext运行完成以后回调所有的SpringApplicationRunListener的contextLoaded();
7_2.springboot2.x启动配置原理_2.运行run方法的更多相关文章
- 7_1.springboot2.x启动配置原理_1.创建SpringApplication对象
环境准备 springboot2.1.9.idea2019. pom.xml 解析 几个重要的事件回调机制 配置在META-INF/spring.factories ApplicationContex ...
- 7_3.springboot2.x启动配置原理_3.事件监听机制
事件监听机制配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunListenerioc容器中的 ...
- 【SpringBoot1.x】SpringBoot1.x 启动配置原理 和 自定义starter
SpringBoot1.x 启动配置原理 和 自定义starter 启动配置原理 本节源码 启动过程主要为: new SpringApplication(sources) 创建 SpringAppli ...
- 七、Spring Boot 启动配置原理
几个重要的事件回调机制 配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunListener ...
- Spring boot 启动配置原理
配置在META-INF/spring.factories 有几个主要的类 ApplicationContextInitializer 创建SpringAplication SpringAppli ...
- SpringBoot的启动配置原理
一.启动流程 创建SpringApplication对象 public class SpringApplication { public SpringApplication(Class... prim ...
- 【串线篇】spring boot启动配置原理
几个重要的事件回调机制 配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunListener ...
- springboot 启动配置原理【转】【补】
创建应用 几个重要的事件回调机制 , 配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunL ...
- SpringBoot 启动配置原理
几个重要的事件回调机制 ApplicationContextInitializer SpringApplicationRunListener ApplicationRunner CommandLine ...
随机推荐
- Linux基本使用命令
一.常用命令归纳分类 课外网站 http://man.linuxde.net/ http://www.jb51.net/linux/ http ...
- Delphi 一些pas
Delphi -- 创建 桌面.发送到....快速启动栏.开始菜单.程序菜单.右键菜 单 {====================================================== ...
- [JZOJ 5813] 计算
题意:求满足题意的方案数. 思路: 显然的计数类\(dp\). 不难发现,令$f(x) = \prod_{i=1}^{2m}{x_i} \(. 在找一个\)x'\(使得\)f(x') = \prod_ ...
- [JZOJ 5812] 区间
题意:求经过多少次操作可以使得序列达到给定状态. 思路: 好像和\(CF\)某次比赛的题差不多啊... 差分统计每个点的值,将临近的\(+1\)和\(-1\)匹配即可. #include <bi ...
- git 安装 使用过程遇到的问题
git add "文件名"->git commit -m 'add' ->>git push origin develop 1.git基础之切换分支 选择gi ...
- nginx按日分割日志
#!/bin/bash #按日切割nginx日志并压缩,加入crontab每天0:00切割 #作者:fafu_li #时间: source /etc/profile #加载系统环境变量 source ...
- jQuery 表单域选中选择器
复选框.单选按钮.下拉列表 /***********************************************/ <script type="text/javascrip ...
- CodeForces 1152F1 Neko Rules the Catniverse (Small Version)
题目链接:http://codeforces.com/problemset/problem/1152/F1 题目大意 有 n 个星球,给定限制 m,从 x 星球走到 y 星球的条件是,$1 \leq ...
- Day 13 : 函数递归,
从前有有座山,山里有座庙,庙里有个老和尚给小和尚们讲故事,讲的什么呀,讲的是,从前有有座山,山里有座庙,庙里有个老和尚给小和尚们讲故事,讲的什么呀?讲的是?...... 递归:1.一个函数再内部调用了 ...
- C盘清理垃圾
经常清理C盘垃圾,会让系统运行更快,避免死机,今天教大家一种简单实用的方法,用文本文档清理垃圾: 1:在电脑桌面空白处右键-建立文本文档: 2:把以下代码复制到文本里 @echo offecho 正在 ...