zoukankan      html  css  js  c++  java
  • Spring源码情操陶冶-AbstractApplicationContext#registerListeners

    承接前文Spring源码情操陶冶-AbstractApplicationContext#onRefresh
    约定web.xml配置的contextClass为默认值XmlWebApplicationContext

    直接源码AbstractRefreshableWebApplicationContext#registerListeners

    	/**
    	 * Add beans that implement ApplicationListener as listeners.
    	 * Doesn't affect other listeners, which can be added without being beans.
    	 */
    	protected void registerListeners() {
    		// Register statically specified listeners first.
    		for (ApplicationListener<?> listener : getApplicationListeners()) {
    			getApplicationEventMulticaster().addApplicationListener(listener);
    		}
    
    		// Do not initialize FactoryBeans here: We need to leave all regular beans
    		// uninitialized to let post-processors apply to them!
    		//从DefaultListableFactory中获取ApplicationListener beans
    		String[] listenerBeanNames = getBeanNamesForType(ApplicationListener.class, true, false);
    		for (String listenerBeanName : listenerBeanNames) {
    			//放入前文创建的SimpleApplicationEventMultlcaster中
    			getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName);
    		}
    
    		// Publish early application events now that we finally have a multicaster...
    		Set<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents;
    		//设置earlyApplicationEvents集合为空,让finishRefresh()可执行剩下的ApplicationEvent
    		this.earlyApplicationEvents = null;
    		if (earlyEventsToProcess != null) {
    			for (ApplicationEvent earlyEvent : earlyEventsToProcess) {
    				getApplicationEventMulticaster().multicastEvent(earlyEvent);
    			}
    		}
    	}
    

    注册ApplicationListener beans到广播集合中,并执行earlyApplicationEvents中的事件,一般为空

    下节预告

    Spring源码情操陶冶-AbstractApplicationContext#finishBeanFactoryInitialization

  • 相关阅读:
    uoj35 后缀排序
    bzoj1026windy数
    poj2761 feed the dog
    codevs2875RY哥查字典
    bzoj1683[Usaco2005 Nov]City skyline 城市地平线
    codevs2464超级麻将
    初赛乱记
    让NOI Linux变得可用
    [HAOI2015] 按位或
    一句话CF
  • 原文地址:https://www.cnblogs.com/question-sky/p/6843036.html
Copyright © 2011-2022 走看看