Spring boot启动加载嵌入的tomcat过程:

1、执行SpringApplication.run方法。进入这个方法,会有一个refreshContext(context);方法。其中的context是spring boot自定义的一个类EmbeddedWebApplicationContext继承了AbstractApplicationContext(); 重写封装了其中的onRefresh和finishRefresh方法。

2、开始执行context覆盖的refresh方法,其实内部就是去执行父级的refresh方法。

Spring boot启动加载嵌入的tomcat过程

Spring boot启动加载嵌入的tomcat过程

Spring boot启动加载嵌入的tomcat过程

3、执行this.onRefresh方法,这个是有自定义的context类覆盖重写了。

Spring boot启动加载嵌入的tomcat过程

Spring boot启动加载嵌入的tomcat过程

先执行父级的方法,再创建一个servletContainer容器。这里获取容器有jetty ,tomcat,undertow三种容器的实现。

进入到TomcatEmbeddedServletContainerFactory中,会有new Tomcat和设置端口等信息。

Spring boot启动加载嵌入的tomcat过程

4、执行AbstractApplicationContext的this.finishRefresh方法,自定义的context覆盖了该方法。

Spring boot启动加载嵌入的tomcat过程

Spring boot启动加载嵌入的tomcat过程

Spring boot启动加载嵌入的tomcat过程

调用TomcatEmbeddedServletContainer的start()方法,里面会执行startConnector方法执行tomcat的启动。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-11-25
  • 2021-10-01
  • 2021-06-22
  • 2022-03-03
  • 2021-08-22
猜你喜欢
  • 2021-11-14
  • 2021-06-01
  • 2021-08-21
  • 2021-12-20
  • 2021-03-13
  • 2022-12-23
  • 2022-01-25
相关资源
相似解决方案