springboot内置Tomcat流程

1、org.springframework.boot.SpringApplication#initialize

java 复制代码
setInitializers((Collection) getSpringFactoriesInstances(
				ApplicationContextInitializer.class));

加载了org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext

2、spring refresh 中onRefresh回调中启动了内置Tomcat

ServletWebServerApplicationContext继承AbstractApplicationContext,并且重新实现了onRefresh方法。

java 复制代码
	//重写了refresh方法,启动
    @Override
	protected void onRefresh() {
		super.onRefresh();
		try {
			createWebServer();
		}
		catch (Throwable ex) {
			throw new ApplicationContextException("Unable to start web server", ex);
		}
	}

    //启动Tomcat
	private void createWebServer() {
		WebServer webServer = this.webServer;
		ServletContext servletContext = getServletContext();
		if (webServer == null && servletContext == null) {
			ServletWebServerFactory factory = getWebServerFactory();
			this.webServer = factory.getWebServer(getSelfInitializer());
		}
		else if (servletContext != null) {
			try {
				getSelfInitializer().onStartup(servletContext);
			}
			catch (ServletException ex) {
				throw new ApplicationContextException("Cannot initialize servlet context", ex);
			}
		}
		initPropertySources();
	}

    //如果Tomcat启动了,就发布服务ServletWebServerInitializedEvent
	@Override
	protected void finishRefresh() {
		super.finishRefresh();
		WebServer webServer = startWebServer();
		if (webServer != null) {
			publishEvent(new ServletWebServerInitializedEvent(webServer, this));
		}
	}
    
相关推荐
十五喵源码网6 天前
基于springboot2+vue2的租房管理系统
java·毕业设计·springboot·论文笔记
vx-Biye_Design6 天前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis
whaledown6 天前
Kafka 与 Java 消息队列入门:用订单场景理解核心机制
java·kafka·消息队列·springboot
二哈赛车手6 天前
新人笔记---最终版智能体图片分析完整方案,包括一些总结于经验,以及各种优化点讲解
java·笔记·spring·ai·springboot
kakawzw7 天前
Tomcat源码笔记1——连接器(Tomcat4默认)
tomcat
十五喵源码网7 天前
基于SpringBoot2+vue2的酒店客房管理系统
java·毕业设计·springboot·论文笔记
这里是杨杨吖8 天前
SpringBoot+Vue高校在线考试系统 附带详细运行指导视频
vue·在线考试·springboot
2601_961875248 天前
法考备考计划表|学习计划|资料已整理
java·开发语言·学习·eclipse·tomcat·c#·hibernate
就改了8 天前
ElasticsearchRestTemplate使用方法详解!!!
java·elasticsearch·springboot
极创信息9 天前
Linux挖矿病毒深度清理实战教程,从进程隐藏、Rootkit驻留到彻底根除
java·大数据·linux·运维·安全·tomcat·健康医疗