10_注册监听器

查看全部
// Check for listener beans and register them.
registerListeners();

  1. 注册静态指定的监听器,加入到事件多播器中
// Register statically specified listeners first.
for (ApplicationListener listener : getApplicationListeners()) {
    getApplicationEventMulticaster().addApplicationListener(listener);
}
  1. 找到所有的ApplicationListener, 注册并加入到事件多播器中
String[] listenerBeanNames = getBeanNamesForType(ApplicationListener.class, true, false);
for (String listenerBeanName : listenerBeanNames) {
    getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName);
}
  1. 用刚刚注册的事件多播器派发之前早期产生的事件,并将之前的事件清空
// Publish early application events now that we finally have a multicaster...
Set earlyEventsToProcess = this.earlyApplicationEvents;
this.earlyApplicationEvents = null;
if (earlyEventsToProcess != null) {
    for (ApplicationEvent earlyEvent : earlyEventsToProcess) {
        getApplicationEventMulticaster().multicastEvent(earlyEvent);
    }
}

你可能感兴趣的:(10_注册监听器)