spring boot学习之tomcat与spring boot

本文探讨了Spring Boot如何与Tomcat集成,包括Spring Boot内置Tomcat的启动过程,以及如何在不使用web.xml的情况下进行外置Tomcat部署。通过ServletWebServerApplicationContext的生命周期方法和SpringServletContainerInitializer的实现,解释了Spring Boot支持基于注解的应用启动模式。
摘要由CSDN通过智能技术生成

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.容器启动时期ServletWebServerApplicationContext的

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值