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

  • 相关阅读:
    MyEclipse中代码提醒功能
    oracle12c创建用户等问题
    java中的构造块、静态块等说明
    jquery中的get和post、ajax有关返回值的问题描述
    最大半连通子图 BZOJ 1093
    最小生成树计数 BZOJ 1016
    水平可见直线 BZOJ 1007
    分金币 BZOJ 3293
    游走 BZOJ 3143
    糖果 BZOJ 2330
  • 原文地址:https://www.cnblogs.com/question-sky/p/6843036.html
Copyright © 2011-2022 走看看