zoukankan      html  css  js  c++  java
  • spring boot 源码之SpringApplicationRunListeners

    SpringApplicationRunListeners

      SpringApplicationRunListener的集合,内部存储了SpringApplicationRunListener的集合,提供了SpringApplicationRunListener一样方法,方便统一遍历调用所有SpringApplicationRunListener。

    private final List<SpringApplicationRunListener> listeners;
        SpringApplicationRunListeners(Log log,
                Collection<? extends SpringApplicationRunListener> listeners) {
            this.log = log;
            this.listeners = new ArrayList<>(listeners);
        }
        public void starting() {
            for (SpringApplicationRunListener listener : this.listeners) {
                listener.starting();
            }
        }
        public void environmentPrepared(ConfigurableEnvironment environment) {
            for (SpringApplicationRunListener listener : this.listeners) {
                listener.environmentPrepared(environment);
            }
        }
        public void contextPrepared(ConfigurableApplicationContext context) {
            for (SpringApplicationRunListener listener : this.listeners) {
                listener.contextPrepared(context);
            }
        }
        public void contextLoaded(ConfigurableApplicationContext context) {
            for (SpringApplicationRunListener listener : this.listeners) {
                listener.contextLoaded(context);
            }
        }
        public void finished(ConfigurableApplicationContext context, Throwable exception) {
            for (SpringApplicationRunListener listener : this.listeners) {
                callFinishedListener(listener, context, exception);
            }
        }

    SpringApplicationRunListener

      springApplication运行的监听器,在相应的节点执行回调方法。

    public interface SpringApplicationRunListener {
    
        /**
         * springApplication的run方法一执行就调用。
         */
        void starting();
    
        /**
         * Called once the environment has been prepared, but before the
         * {@link ApplicationContext} has been created.
         * @param environment the environment
         */
        void environmentPrepared(ConfigurableEnvironment environment);
    
        /**
         * Called once the {@link ApplicationContext} has been created and prepared, but
         * before sources have been loaded.
         * @param context the application context
         */
        void contextPrepared(ConfigurableApplicationContext context);
    
        /**
         * Called once the application context has been loaded but before it has been
         * refreshed.
         * @param context the application context
         */
        void contextLoaded(ConfigurableApplicationContext context);
    
        /**
         * 在springApplication的run方法完成前被调用*/
        void finished(ConfigurableApplicationContext context, Throwable exception);
    
    }
  • 相关阅读:
    jsp_Scriptlet
    jsp_注释
    Http状态码详解
    Tomcat服务器的安装和配置
    【BZOJ 1018】线段树 **
    【BZOJ 2054】 2054: 疯狂的馒头 (并查集特技)
    【BZOJ 1969】 1969: [Ahoi2005]LANE 航线规划 (树链剖分+线段树)
    【BZOJ 1880】 [Sdoi2009]Elaxia的路线 (最短路树)
    【UOJ 79】 一般图最大匹配 (✿带花树开花)
    【UOJ 34】 多项式乘法 (FFT)
  • 原文地址:https://www.cnblogs.com/zhangwanhua/p/7940838.html
Copyright © 2011-2022 走看看