10_注册监听器

2020-01-09  本文已影响0人  steamed_bun

\underline{spring容器刷新第十步}查看全部
// 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<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents;
this.earlyApplicationEvents = null;
if (earlyEventsToProcess != null) {
    for (ApplicationEvent earlyEvent : earlyEventsToProcess) {
        getApplicationEventMulticaster().multicastEvent(earlyEvent);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读