1.ContextLoaderListener

1.1.ContextLoaderListener源码

public class ContextLoaderListener extends ContextLoader implements ServletContextListener {
...
}

ServletContextListener源码:

public interface ServletContextListener extends EventListener {

/<strong>
web容器启动后,调用
</strong>/
public default void contextInitialized(ServletContextEvent sce) {
}
/<strong>
web容器关闭时调用,web将要关闭,还未关闭
</strong>/
public default void contextDestroyed(ServletContextEvent sce) {
}
}

ContextLoader: 用于spring 容器初始化类

public class ContextLoader {
...
}

1.2.流程

Spring ApplicationContext启动方式_web容器

2.springBoot方式

2.1.流程

Spring ApplicationContext启动方式_初始化_02

2.2.ServletWebServerApplicationContext

springboot在执行SpringAppliction.run方法时,创建的ApplicationContext是ServletWebServerApplicationContext,
改context实现了 AbstractApplicationContext.onRefresh方法,在onRefresh方法中创建了相应的web容器。