SpringBoot(3)-启动流程

SpringBoot(3)-启动流程


前言

Tomcat
扩展:

概念

Tomcat

  • Tomcat是怎么加载的
1、ServletWebServerFactoryAutoConfiguration

2、ServerProperties


1.1
//对Tomcat进行初始化
@ConditionalOnClass(name = "org.apache.catalina.startup.Tomcat")
public TomcatServletWebServerFactoryCustomizer tomcatServletWebServerFactoryCustomizer
1.1.1
WebServerFactoryCustomizer

1.2
Import
ServletWebServerFactoryConfiguration.EmbeddedTomcat.class

1.2.1
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ Servlet.class, Tomcat.class, UpgradeProtocol.class })
@ConditionalOnMissingBean(value = ServletWebServerFactory.class, search = SearchStrategy.CURRENT)
static class EmbeddedTomcat {}
1.2.2  
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getWebServer
是哪里调用的?
1.2.2.1
SpringBoot的启动流程
org.springframework.context.support.AbstractApplicationContext#onRefresh
1.2.2.2
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#onRefresh

1.2.3
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getTomcatWebServer
1.2.4
org.springframework.boot.web.embedded.tomcat.TomcatWebServer#TomcatWebServer(org.apache.catalina.startup.Tomcat, boolean, org.springframework.boot.web.server.Shutdown)
1.2.5
org.springframework.boot.web.embedded.tomcat.TomcatWebServer#initialize
  • SpringBoot加载流程
ApplicationContextInitializer:Context初始化后的类
SpringApplicationRunListener:SpringBoot运行监听的的类,整个springboot的启动流程

启动后操作
ApplicationRunner
CommandLineRunner

1 新建SpringApplication对象,添加监听器
org.springframework.boot.SpringApplication#SpringApplication(org.springframework.core.io.ResourceLoader, java.lang.Class<?>...)

2 run
org.springframework.boot.SpringApplication#run(java.lang.String...)

3 加载 SpringApplicationRunListener 
org.springframework.boot.SpringApplication#getRunListeners

4 准备环境,绑定到Spring上下文
org.springframework.boot.SpringApplication#prepareEnvironment

5 打印banner
org.springframework.boot.SpringApplication#printBanner

6 创建上下文  WebApplicationType Servlet
org.springframework.boot.ApplicationContextFactory#create

7 准备上下文
org.springframework.boot.SpringApplication#prepareContext
7.1 
org.springframework.boot.SpringApplicationRunListeners#contextPrepared
7.2
org.springframework.boot.SpringApplicationRunListeners#contextLoaded

8 注册shutdown Hook  刷新上下文 接轨spring
org.springframework.boot.SpringApplication#refreshContext

9 运行ApplicationRunner CommandLineRunner 
org.springframework.boot.SpringApplication#callRunners

10 执行running
org.springframework.boot.SpringApplicationRunListeners#running


  • spring.factories
org.springframework.context.ApplicationContextInitializer=\
com.today.roc.springboot.running.RocApplicationContextInitializer
  
org.springframework.boot.SpringApplicationRunListener=\
com.today.roc.springboot.running.RocSpringApplicationRunListerner

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值