Spring啓動執行流程

本文是Spring版本5.0.7的

在搭建SSM項目是都需要在web.xml文件裏面配置一個監聽器以及啓動參數(context-param)如下:


	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring-*.xml</param-value>
	</context-param>
	<!-- 監聽器 -->

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

先來張圖
在這裏插入圖片描述

web容器啓動時Spring啓動流程:
1.通過監聽器執行ContextLoaderListener.
2.初始化ContextLoaderListener裏面的Contextinitialed方法
3.初始化父類(ContextLoader)的initContextApplicationContext方法

在這裏插入圖片描述
4.在initContextApplicationContext方法中要執行三個任務
①創建WebApplicationContext容器
在這裏插入圖片描述
②加載context-param中配置的spring配置文件
③初始化配置文件中及創建配置文件中的bean
在這裏插入圖片描述
5.web容器停止時候會執行ContextLoaderListener的contextDestroyed方法銷燬context容器
在這裏插入圖片描述


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章