Spring boot execution process sorting

注:本文梳理启动流程使用的Spring版本:4.0.2.RELEASE
To use spring configuration, you need to configure a spring listener and startup parameter (context-param) in web.xml, as follows:

    <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>

When the web container starts, the following steps are executed for spring loading:

  1. Execute the ContextLoaderListener listener in web.xml
  2. Initialize the contextInitialized method in ContextLoaderListener
    Initialize loading contextInitialized method
  3. The initWebApplicationContext method of the parent class (ContextLoader) is called in the contextInitialized method
    write picture description here
  4. Three tasks are performed in the initWebApplicationContext method
    • Create the WebApplicationContext container
      write picture description here
    • Load the spring configuration file configured in context-param
    • Initialize the bean in the configuration file and create the bean in the configuration file
      write picture description here
      write picture description here

When the web container stops, the contextDestroyed method of ContextLoaderListener will be executed to destroy the context container
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324522306&siteId=291194637