springboot源码解读
springboot源码从main函数开始
public static void main(String[] args) {
ApplicationContext app = SpringApplication.run(BeikbankApplication.class, args);
}
进入run方法,再持续进入到实际操作的步骤
public static ConfigurableApplicationContext run(Object source, String... args) {
return run(new Object[] { source }, args);
}
public static ConfigurableApplicationContext run(Object[] sources, String[] args) {
return new SpringApplication(sources).run(args);
}
public ConfigurableApplicationContext run(String... args) {
//秒表计时器,用来记录整个容器启动时间
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
FailureAnalyzers analyzers = null;
//配置headless系统属性
configureHeadlessProperty();
//获取springbootApplication注解的类信息开启监听
SpringApplicationRunListeners listeners = getRunListeners(args);
listeners.starting();
try {
//应用参数初始化
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args);
//环境变量初始化
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments);
//打印banner,就是spring图形
Banner printedBanner = printBanner(environment);
//创建应用上下文,默认会得到AnnotationConfigEmbeddedWebApplicationContext
context = createApplicationContext();
//反射加载实例化FailureAnalyzer实现类
analyzers = new FailureAnalyzers(context);
//上下文环境准备
prepareContext(context, environment, listeners, applicationArguments,
printedBanner);
//主要的IOC过程,也是springMVC的主要过程,进行bean的相关接口初始化和bean实例化
refreshContext(context);
//到上一步tomcat已经启动完成了,这里算是springboot的扩展接口,可以自己实现ApplicationRunner或CommandLineRunner接口,在这里进行实例化开始运行
afterRefresh(context, applicationArguments);
//发布事件监听器
listeners.finished(context, null);
//停止计时
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass)
.logStarted(getApplicationLog(), stopWatch);
}
return context;
}
catch (Throwable ex) {
handleRunFailure(context, listeners, analyzers, ex);
throw new IllegalStateException(ex);
}
}
我把主要步骤的每一步都标明了注释,看起来这里很多都是springboot特有,但主要的实现还是对springMVC的继承,你去看springmvc的源码,会发现,它主要的过程就是refreshContext这个方法所展现的过程
springboot源码解读的更多相关文章
- SpringBoot源码解读系列三——引导注解
我们再来看下SpringBoot应用的启动类: 查看代码 import org.springframework.boot.SpringApplication; import org.springfra ...
- springboot源码解读01
package org.springframework.web; @javax.servlet.annotation.HandlesTypes({org.springframework.web.Web ...
- SpringBoot源码解读系列——开篇
什么是SpringBoot? 定义可以参考官网:SpringBoot官网,其定义通俗易懂,这里就不赘述. 官网也给出了一个通用的SpringBoot工程样例,其中包含了这么几个元素: 1.pom依赖 ...
- Mybatis源码解读-SpringBoot中配置加载和Mapper的生成
本文mybatis-spring-boot探讨在springboot工程中mybatis相关对象的注册与加载. 建议先了解mybatis在spring中的使用和springboot自动装载机制,再看此 ...
- KClient——kafka消息中间件源码解读
目录 kclient消息中间件 kclient-processor top.ninwoo.kclient.app.KClientApplication top.ninwoo.kclient.app.K ...
- 助力SpringBoot自动配置的条件注解ConditionalOnXXX分析--SpringBoot源码(三)
注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 1 前言 本篇接 如何分析SpringBoot源码模块及结构?--SpringBoot源码(二) 上一篇分析了SpringBoo ...
- 如何分析SpringBoot源码模块及结构?--SpringBoot源码(二)
注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 1 前言 本篇接 如何搭建自己的SpringBoot源码调试环境?--SpringBoot源码(一). 前面搭建好了自己本地的S ...
- SpringApplication对象是如何构建的? SpringBoot源码(八)
注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 本篇接 SpringBoot的启动流程是怎样的?SpringBoot源码(七) 1 温故而知新 温故而知新,我们来简单回顾一下上 ...
- springboot源码解析-管中窥豹系列之项目类型(二)
一.前言 Springboot源码解析是一件大工程,逐行逐句的去研究代码,会很枯燥,也不容易坚持下去. 我们不追求大而全,而是试着每次去研究一个小知识点,最终聚沙成塔,这就是我们的springboot ...
随机推荐
- Connection reset by peer原理解析
“Connection reset by peer”代表什么?“Connection reset by peer”表示当前服务器接受到了通信对端发送的TCP RST信号,即通信对端已经关闭了连接,通过 ...
- 高性能迷你React框架anujs1.0.8发布
本版本由于得到业务线同学的大力支持,掀出许多问题,因此改进地方良多,为anujs在完美替换React的道路上前进了不少.现在anujs经测试可以运行于IE7中.至少怎么做可以参看官网,https:// ...
- unshift() 方法将一个或多个元素添加到数组的开头,并返回新数组的长度
var arr = [1, 2]; arr.unshift(0); //result of call is 3, the new array length //arr is [0, 1, 2] arr ...
- MFC笔记7
1.VS中显示行号 工具 -> 选项 -> 文本编辑器 -> C/C++ -> 行号 2.VS中调整字体大小 工具 -> 选项 -> 环境->字体和颜色 3. ...
- k8s之创建etcd集群
主机规划 maste01——192.168.10.63 master02——192.168.10.64 node01——192.168.10.65 node02——192.168.10.66 1.为保 ...
- win server 2012 服务器不能ping通
以windows server 2012作为服务器,服务器能够ping通局域网中的客户端A,但A不能ping通服务器. 解决办法: 确定服务器中系统->远程设置->远程桌面选项下为允许选项 ...
- MySQL 5.7.9版本sql_mode=only_full_group_by
这会导致select中只能出现group by后面出现的表的字段. 其实如果使用其他表的字段,聚合函数对无法对应其他表的字段. 建议放在子查询里. 如果想打破这个规则,可以设置sql_mode变量,将 ...
- linux resin 安装 配置 相关
resin跟tomcat一样,也是解析jsp网站的,也需要JDK的支持,所以第一步也是安装JDK,安装JDK的方法参考Tomcat中的安装JDK部分.下面介绍安装resin.resin官网http:/ ...
- Eigen子矩阵操作
1 子矩阵操作简介 子矩阵操作又称块操作,在矩阵运算中,子矩阵的提取和操作应用也十分广泛.因此Eigen中也提供了相关操作的方法.提取的子矩阵在操作过程中既可以用作左值也可以用作右值. 2 块操作的一 ...
- Java之IO流总结
IO流·Java流式输入/输出原理·Java流类的分类·输入/输出流类·常见的节点流和处理流·文件流·缓冲流·转换流·数据流·Print流·Object流 ①Java流式输入/输出原理 ...