SpringBoot项目中tomcat容器启动流程

目录

1.项目启动类的main方法执行

2.执行run方法

3.Spring容器初始化

4.Spring容器初始化后的回调

5.创建WebServer

6.获取WebServerFactory

7.获取WebServer,创建并设置Tomcat相关对象属性

8.封装TomcatWebServer

9.初始化TomcatWebServer并启动Tomcat

1.项目启动类的main方法执行

2.执行run方法

经过一系列run的重载方法后,最终调到org.springframework.boot.SpringApplication#run

3.Spring容器初始化

执行前置方法后,调用org.springframework.boot.SpringApplication#refreshContext解析配置类,启动WebServer,最终调用Spring定义的接口方法:org.springframework.context.ConfigurableApplicationContext#refresh,ConfigurableApplicationContext在SpringBoot中有二个实现类ServletWebServerApplicationContext和ReactiveWebServerApplicationContext

此处调用的是org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#refresh,实际调用的是Spring提供抽象父类的方法org.springframework.context.support.AbstractApplicationContext#refresh

4.Spring容器初始化后的回调

spring容器启动完成后,会调用onRefresh方法,实际调用的是SpringBoot提供的子类中的方法org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#onRefresh

5.创建WebServer

org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#createWebServer

6.获取WebServerFactory

org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#getWebServerFactory

 ServletWebServerFactory接口有多个实现类,下面标红的3个就是常用的三个web容器(tomcat/jetty/undertom),启动tomcat用的是TomcatServletWebServerFactory

 7.获取WebServer,创建并设置Tomcat相关对象属性

org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getWebServer

 8.封装TomcatWebServer

org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getTomcatWebServer

 9.初始化TomcatWebServer并启动Tomcat

org.springframework.boot.web.embedded.tomcat.TomcatWebServer#TomcatWebServer

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值