关于spring:Spring-ApplicationContext启动方式

1次阅读

共计 679 个字符,预计需要花费 2 分钟才能阅读完成。

1.ContextLoaderListener

1.1.ContextLoaderListener 源码

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

ServletContextListener 源码:

public interface ServletContextListener extends EventListener {

    /**
    web 容器启动后,调用
    **/
    public default void contextInitialized(ServletContextEvent sce) { }
   /**
    web 容器敞开时调用,web 将要敞开,还未敞开
    **/
    public default void contextDestroyed(ServletContextEvent sce) {}}

ContextLoader: 用于 spring 容器初始化类

public class ContextLoader {...}

1.2. 流程

2.springBoot 形式

2.1. 流程

2.2.ServletWebServerApplicationContext

springboot 在执行 SpringAppliction.run 办法时,创立的 ApplicationContext 是 ServletWebServerApplicationContext,

改 context 实现了 AbstractApplicationContext.onRefresh 办法,在 onRefresh 办法中创立了相应的 web 容器。

正文完
 0