spring boot学习之tomcat与spring boot

tomcat是Servlet容器,spring boot是开发框架,可开发基于Servlet规范的应用
即spring boot应用需要放在Servlet容器上运行
而spring boot可以使用内置Servlet容器启动,也可以发布在外置Servlet容器容器上

内置tomcat之tomcat启动
1.容器构建时期ServletWebServerApplicationContext的onRefresh()

	//在父类AbstractApplicationContext的refresh()中调用
	protected void onRefresh() {
		super.onRefresh();
		try {
		   //创建web容器
			createWebServer();
		}
		catch (Throwable ex) {
			throw new ApplicationContextException("Unable to start web server", ex);
		}
	}
	private void createWebServer() {
		WebServer webServer = this.webServer;
		ServletContext servletContext = getServletContext();
		if (webServer == null && servletContext == null) {
			//main方法启动时会找对应的jar包,没有则报错
			ServletWebServerFactory factory = getWebServerFactory();
			this.webServer = factory.getWebServer(getSelfInitializer());
		}
		else if (servletContext != null) {
			//外置tomcat启动,初始化selvlet context
			try {
				getSelfInitializer().onStartup(servletContext);
			}
			catch (ServletException ex) {
				throw new ApplicationContextException("Cannot initialize servlet context", ex);
			}
		}
		initPropertySources();
	}
	

2.容器启动时期ServletWebServerApplicationConte

你可能感兴趣的:(spring,boot学习,spring,boot,tomcat)