Spring啟動執行流程梳理


注:本文梳理啟動流程使用的Spring版本:4.0.2.RELEASE 使用spring配置,都需要在web.xml中配置一個spring的監聽器和啟動參數(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. 執行web.xml中的ContextLoaderListener監聽器
  2. 初始化ContextLoaderListener中的contextInitialized方法
  3. contextInitialized方法中調用父類(ContextLoader)的initWebApplicationContext方法

  4. initWebApplicationContext方法中執行了三個任務
            1.創建WebApplicationContext容器
           

     


            2.加載context-param中配置的spring配置文件
            3.初始化配置文件中及創建配置文件中的bean
           

     


           

     

  5. web容器停止時候會執行ContextLoaderListener的contextDestroyed方法銷毀context容器

     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM