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));
		}
	}
    
相关推荐
七烦3 小时前
vue3 + springboot实现微信登录
vue·springboot·微信公众号
llwszx12 小时前
一文解决Servlet、Tomcat与HttpServletRequest
java·servlet·tomcat·httpreque
LUCIAZZZ1 天前
项目拓展-Apache对象池,对象池思想结合ThreadLocal复用日志对象
java·jvm·数据库·spring·apache·springboot
LUCIAZZZ2 天前
钉钉机器人-自定义卡片推送快速入门
java·jvm·spring boot·机器人·钉钉·springboot
LUCIAZZZ2 天前
项目拓展-Jol分析本地对象or缓存的内存占用
java·开发语言·jvm·数据库·缓存·springboot
雨果talk2 天前
【一文看懂多模块Bean初始化难题】Spring Boot多模块项目中的Bean初始化难题:包名不一致的优雅解决方案
java·spring boot·后端·spring·springboot
武子康2 天前
Java-46 深入浅出 Tomcat 核心架构 Catalina 容器全解析 启动流程 线程机制
java·开发语言·spring boot·后端·spring·架构·tomcat
草履虫建模3 天前
Tomcat 和 Spring MVC
java·spring boot·spring·spring cloud·tomcat·mvc·intellij-idea
网安INF4 天前
CVE-2020-1938源码分析与漏洞复现(Tomcat 文件包含/读取)
java·网络·web安全·网络安全·tomcat·漏洞复现
GzlAndy4 天前
Tomcat调优
java·tomcat