tomcat載入web應用
阿新 • • 發佈:2020-10-16
文章目錄
前言
tomcat啟動後會載入各個應用的web.xml檔案,通過配置檔案中的資訊載入應用,一般spring應用通常會配置ContextLoaderListener、DispatcherServlet兩個物件完成初始化
一、ContextLoaderListener
監聽tomcat事件後觸發
根據ContextLoader.properties配置,預設建立XmlWebApplicationContext上下文物件
獲取contextConfigLocation配置檔案路徑並賦值給上下文物件,觸發上下文物件的refresh方法
XmlWebApplicationContext繼承AbstractApplicationContext
呼叫AbstractApplicationContext.refresh()
二、DispatcherServlet
DispatcherServlet繼承FrameworkServlet
FrameworkServlet繼承HttpServletBean
tomcat初始化servlet呼叫HttpServletBean.init()
然後呼叫FrameworkServlet.initServletBean(),初始化上下文物件
預設建立XmlWebApplicationContext上下文物件獲取contextConfigLocation配置檔案路徑並賦值給上下文物件,觸發上下文物件的refresh方法