SpringBoot内置Tomcat启动的源码分析

时间:2020-03-29 00:27:37   收藏:0   阅读:93
  1. 完整启动debug流程如下:
>SpringApplication.run(BootStudyApplication.class,args);
 	>org.springframework.boot.SpringApplication#run(java.lang.Class<?>[], java.lang.String[])
 		>org.springframework.boot.SpringApplication#refreshContext
 			>org.springframework.boot.SpringApplication#refresh
 				>org.springframework.context.support.AbstractApplicationContext#refresh
 					>org.springframework.context.support.AbstractApplicationContext#refresh
 						>org.springframework.context.support.AbstractApplicationContext#onRefresh
 							>org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#createWebServer
 								>org.springframework.boot.web.servlet.server.ServletWebServerFactory#getWebServer
 									>org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getTomcatWebServer
 										>org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getTomcatWebServer
 											>org.springframework.boot.web.embedded.tomcat.TomcatWebServer#initialize
 												>org.springframework.boot.web.embedded.tomcat.TomcatWebServer#start

描述:
SpringBoot项目启动会调用Spring刷新容器方法,然后会调用到onRefresh方法,此方法是一个空方法,被子类ServletWebServerApplicationContext覆写,然后他会调用创建web容器的方法,然后创建出一个Tomcat,并且启动Tomcat。

流程图如下:
技术分享图片

  1. 有兴趣自己调试的小伙伴可以写一个SpringBoot项目,把断点打在TomcatWebServer的start方法上,然后往上翻代码即可。

原文:https://www.cnblogs.com/javammc/p/12590155.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!