springboot三大特性
1、帮助开发人员实现快速整合第三方框架,封装maven依赖和自定义startee
2、使用springboot可以完全采用注解化启动项目,注解形式原理,springboot包装了spring springmvc注解启动方式。
3、springboot内嵌tomcat容器,其实就是使用java语言本身创建tomcat服务器
分析springboot源码过程
1、有哪些注解
2、springapplication启动流程分析
3、springboot之tomcat启动流程分析
4、springboot之springmvc启动流程分析
5、springboot启动自定义启动打印信息
springboot启动流程
核心分为两个步骤
1:创建springbootApppplication对象
2、调用springbootApppplication run 启动并返回当前容器上下文
分析流程
1)、创建springbootApppplication对象 springboot容器初始化操作
2)获取当前应用启动类型 判断当前classpsth是否加载有servlet类,返回servlet web启动方式
3)、webapplicationtype有三种类型
1、响应式启动
2、none 不会嵌入web容器启动 将springboot项目放入外部容器中启
3servlet基于web容器启动
3、setlnitializers读取Spr ingBoot包下面的META- |NF/spring. factories获取到对应Appl icat ionContext Initializer装配到集合中,一共是6个
4、setListeners 读取SpringBoot包下面的META- INF/spring.factories获取到对应ApplicationListener装配到集合中
5,mainApplicationClass获取当前运行的主函数
6,调用SpringApplication的run方法实现启动
7,StopWatch stopWatch = new StopWatch();
记录springboot项目启动时间
8,getRunListeners(args)读取所有包里面的META-INF/spring.factories文件中的SpringApplicationRunListener类型存入到集合中
9,listeners.starting();循环执行集合中所有项的starting方法
10,ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
读取配置文件到springboot容器中
11,Banner printedBanner = printBanner(environment);
打印Banner图
12,context = createApplicationContext();
13,refreshContext(context); 刷新上下文
14,开始创建tomcat容器
15,开始加载SpringMVC
16,afterRefresh(context, applicationArguments);
一个空的模板方法,可以供子类重写
17,listeners.started(context);
使用广播和回调机制通知监听器springboot容器已经启动成功
18,listeners.running(context);
使用广播和回调机制通知监听器springboot容器已经启动成功,可以正常运行项目
19,最后返回当前上下文对象
以上原理由每特教育&蚂蚁课堂余老师分析