美文网首页
spring ApplicationContext启动方式

spring ApplicationContext启动方式

作者: 程序猿老徐 | 来源:发表于2022-04-09 11:16 被阅读0次

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.流程

ContextLoaderListener.png

2.springBoot方式

2.1.流程

springBoot启动容器.png

2.2.ServletWebServerApplicationContext

springboot在执行SpringAppliction.run方法时,创建的ApplicationContext是ServletWebServerApplicationContext,

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

相关文章

网友评论

      本文标题:spring ApplicationContext启动方式

      本文链接:https://www.haomeiwen.com/subject/dukpsrtx.html