springboot启动原理

查看链接
总结
springboot原理
包装spring核心注解,使用springmvc无xml进行启动,通过自定义starter和maven依赖简化开发代码,开发者能够快速整合第三方框架,通过java语言内嵌入tomcat

springboot启动流程
--------------------------------创建springbootApplication对象---------------------------------------------

  1. 创建springbootApplication对象springboot容器初始化操作
  2. 获取当前应用的启动类型。
    注1:通过判断当前classpath是否加载servlet类,返回servlet web启动方式。
    注2:webApplicationType三种类型:
    1.reactive:响应式启动(spring5新特性)
    2.none:即不嵌入web容器启动(springboot放在外部服务器运行 )
    3.servlet:基于web容器进行启动
  3. 读取springboot下的META-INFO/spring.factories文件,获取对应的ApplicationContextInitializer装配到集合
  4. 读取springboot下的META-INFO/spring.factories文件,获取对应的ApplicationListener装配到集合
  5. mainApplicationClass,获取当前运行的主函数

------------------调用springbootApplication对象的run方法,实现启动,返回当前容器的上下文----------------------------------------------
7. 调用run方法启动
8. StopWatch stopWatch = new StopWatch(),记录项目启动时间
9. getRunListeners,读取META-INF/spring.factores,将SpringApplicationRunListeners类型存到集合中
10. listeners.starting();循环调用starting方法
11. prepareEnvironment(listeners, applicationArguments);将配置文件读取到容器中
读取多数据源:classpath:/,classpath:/config/,file:./,file:./config/底下。其中classpath是读取编译后的,file是读取编译前的
支持yml,yaml,xml,properties
12. Banner printedBanner = printBanner(environment);开始打印banner图,就是sprongboot启动最开头的图案
13. 初始化AnnotationConfigServletWebServerApplicationContext对象
14. 刷新上下文,调用注解,refreshContext(context);
15. 创建tomcat
16. 加载springmvc
17. 刷新后的方法,空方法,给用户自定义重写afterRefresh()
18. stopWatch.stop();结束计时
19. 使用广播和回调机制告诉监听者springboot容器已经启动化成功,listeners.started(context);
20. 使用广播和回调机制告诉监听者springboot容器已经启动化成功,listeners.started(context);
21. 返回上下文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值