Spring boot启动加载嵌入的tomcat过程:
1、执行SpringApplication.run方法。进入这个方法,会有一个refreshContext(context);方法。其中的context是spring boot自定义的一个类EmbeddedWebApplicationContext继承了AbstractApplicationContext(); 重写封装了其中的onRefresh和finishRefresh方法。
2、开始执行context覆盖的refresh方法,其实内部就是去执行父级的refresh方法。
3、执行this.onRefresh方法,这个是有自定义的context类覆盖重写了。
先执行父级的方法,再创建一个servletContainer容器。这里获取容器有jetty ,tomcat,undertow三种容器的实现。
进入到TomcatEmbeddedServletContainerFactory中,会有new Tomcat和设置端口等信息。
4、执行AbstractApplicationContext的this.finishRefresh方法,自定义的context覆盖了该方法。
调用TomcatEmbeddedServletContainer的start()方法,里面会执行startConnector方法执行tomcat的启动。