当前位置: 首页 > news >正文

SpringBoot复习:(2)Tomcat容器是怎么启动的?

SpringApplication的run方法包含如下代码:
在这里插入图片描述
其中调用的refreshContext代码如下:
在这里插入图片描述
其中调用的refresh方法片段如下:
在这里插入图片描述
其中调用的refresh方法代码如下:
在这里插入图片描述
其中调用的super.refresh方法代码如下:

	public void refresh() throws BeansException, IllegalStateException {synchronized (this.startupShutdownMonitor) {StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");// Prepare this context for refreshing.prepareRefresh();// Tell the subclass to refresh the internal bean factory.ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();// Prepare the bean factory for use in this context.prepareBeanFactory(beanFactory);try {// Allows post-processing of the bean factory in context subclasses.postProcessBeanFactory(beanFactory);StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");// Invoke factory processors registered as beans in the context.invokeBeanFactoryPostProcessors(beanFactory);// Register bean processors that intercept bean creation.registerBeanPostProcessors(beanFactory);beanPostProcess.end();// Initialize message source for this context.initMessageSource();// Initialize event multicaster for this context.initApplicationEventMulticaster();// Initialize other special beans in specific context subclasses.onRefresh();// Check for listener beans and register them.registerListeners();// Instantiate all remaining (non-lazy-init) singletons.finishBeanFactoryInitialization(beanFactory);// Last step: publish corresponding event.finishRefresh();}catch (BeansException ex) {if (logger.isWarnEnabled()) {logger.warn("Exception encountered during context initialization - " +"cancelling refresh attempt: " + ex);}// Destroy already created singletons to avoid dangling resources.destroyBeans();// Reset 'active' flag.cancelRefresh(ex);// Propagate exception to caller.throw ex;}finally {// Reset common introspection caches in Spring's core, since we// might not ever need metadata for singleton beans anymore...resetCommonCaches();contextRefresh.end();}}}

其中调用了onRefresh方法:
在这里插入图片描述
进入

ServletWebServerApplicationContext的onRefresh方法:
在这里插入图片描述
createWebServer代码如下:
在这里插入图片描述
其中调用的TomcatServletWebServerFactory的getWebServer代码如下:
在这里插入图片描述
其中调用的getTomcatWebServer的代码如下:
在这里插入图片描述
其中调用的构造方法如下:
在这里插入图片描述
其中调用的initialize方法代码如下:

	private void initialize() throws WebServerException {logger.info("Tomcat initialized with port(s): " + getPortsDescription(false));synchronized (this.monitor) {try {addInstanceIdToEngineName();Context context = findContext();context.addLifecycleListener((event) -> {if (context.equals(event.getSource()) && Lifecycle.START_EVENT.equals(event.getType())) {// Remove service connectors so that protocol binding doesn't// happen when the service is started.removeServiceConnectors();}});// Start the server to trigger initialization listenersthis.tomcat.start();// We can re-throw failure exception directly in the main threadrethrowDeferredStartupExceptions();try {ContextBindings.bindClassLoader(context, context.getNamingToken(), getClass().getClassLoader());}catch (NamingException ex) {// Naming is not enabled. Continue}// Unlike Jetty, all Tomcat threads are daemon threads. We create a// blocking non-daemon to stop immediate shutdownstartDaemonAwaitThread();}catch (Exception ex) {stopSilently();destroySilently();throw new WebServerException("Unable to start embedded Tomcat", ex);}}}

其中可以看到启动tomcat的代码:
在这里插入图片描述

http://www.lryc.cn/news/101121.html

相关文章:

  • 1 MobileHomeTopicApplication
  • mpi4py包安装报错
  • C语言进阶-1
  • Python如何正确解决爬虫过程中的Cookie失效问题?
  • 维护自己电脑浅析
  • svo2论文
  • 【GoLang】MAC安装Go语言环境
  • epoll服务器创建
  • jdk11环境 提示“因为 accessExternalDTD 属性设置的限制导致不允许 ‘http‘ 访问“bug
  • Android Studio 的版本控制Git
  • 一个 SpringBoot 项目能处理多少请求
  • Python中的r字符串前缀及其用法详解
  • LabVIEW实现三相异步电机磁通模型
  • 读书会-《影响力》
  • 141. 环形链表
  • 学习笔记|大模型优质Prompt开发与应用课(二)|第一节:大模型应用密码—Prompt的一千种打开方式
  • QT chart进行画图
  • Web3将自己写在合约中的代币添加到MetaMask中管理
  • 【微信小程序】显示自带的弹窗,包括加载中,成功,错误,提示,警告
  • vue-element-plus-admin框架的tag上下文切换bug
  • vue中,父子组件传递参数 props 实现方式
  • Unity如何快速接入iOS和GooglePlay的成就排行榜等GameCenter功能
  • Unity下如何实现低延迟的全景RTMP|RTSP流渲染
  • STM32 USB使用记录:HID类设备(后篇)
  • C# 快速写入日志 不卡线程 生产者 消费者模式
  • Pandas将对角线元素设为1
  • WPF实战学习笔记28-登录界面
  • 01背包
  • 064、故障处理之OMM_TiDB
  • 网络设备中的配置文件管理