本文介绍: 加载org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext。ServletWebServerApplicationContext继承AbstractApplicationContext,并且重新实现了onRefresh方法。2、spring refresh 中onRefresh回调中启动了内置Tomcat。

1、org.springframework.boot.SpringApplication#initialize

setInitializers((Collection) getSpringFactoriesInstances(
				ApplicationContextInitializer.class));

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

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

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

	//重写了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));
		}
	}
    

原文地址:https://blog.csdn.net/lyyCSDNBLOG/article/details/134560040

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_2323.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注