1. 程式人生 > 實用技巧 >tomcat載入web應用

tomcat載入web應用

文章目錄


前言

tomcat啟動後會載入各個應用的web.xml檔案,通過配置檔案中的資訊載入應用,一般spring應用通常會配置ContextLoaderListener、DispatcherServlet兩個物件完成初始化

一、ContextLoaderListener

監聽tomcat事件後觸發
監聽tomcat事件後觸發
根據ContextLoader.properties配置,預設建立XmlWebApplicationContext上下文物件
獲取contextConfigLocation配置檔案路徑並賦值給上下文物件,觸發上下文物件的refresh方法

初始化上下文物件
XmlWebApplicationContext繼承AbstractApplicationContext
呼叫AbstractApplicationContext.refresh()
上下文refresh

二、DispatcherServlet

DispatcherServlet繼承FrameworkServlet
FrameworkServlet繼承HttpServletBean
tomcat初始化servlet呼叫HttpServletBean.init()
servlet初始化入口

然後呼叫FrameworkServlet.initServletBean(),初始化上下文物件
初始化上下文物件
預設建立XmlWebApplicationContext上下文物件獲取contextConfigLocation配置檔案路徑並賦值給上下文物件,觸發上下文物件的refresh方法

呼叫DispatcherServlet.onRefresh完成webmvc的功能初始化
上下文物件初始化
webmvc初始化

引用

web.xml的載入過程配置詳解