欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ApplicationListenerDetector監(jiān)聽器判斷demo

 更新時間:2023年03月14日 14:43:52   作者:無名之輩J  
這篇文章主要為大家介紹了ApplicationListenerDetector監(jiān)聽器判斷demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

Bean實例化之后

判斷Bean是否是監(jiān)聽器,如果是監(jiān)聽器就將當前Bean加入監(jiān)聽器集合

public Object postProcessAfterInitialization(Object bean, String beanName) {
   if (bean instanceof ApplicationListener) {
      // potentially not detected as a listener by getBeanNamesForType retrieval
      Boolean flag = this.singletonNames.get(beanName);
      if (Boolean.TRUE.equals(flag)) {
         // singleton bean (top-level or inner): register on the fly
         this.applicationContext.addApplicationListener((ApplicationListener<?>) bean);
      }
      else if (Boolean.FALSE.equals(flag)) {
         if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) {
            // inner bean with other scope - can't reliably process events
            logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " +
                  "but is not reachable for event multicasting by its containing ApplicationContext " +
                  "because it does not have singleton scope. Only top-level listener beans are allowed " +
                  "to be of non-singleton scope.");
         }
         this.singletonNames.remove(beanName);
      }
   }
   return bean;
}

Bean銷毀之前

如果當前Bean是監(jiān)聽器,就將當前Bean從監(jiān)聽器集合中移除

public void postProcessBeforeDestruction(Object bean, String beanName) {
   if (bean instanceof ApplicationListener) {
      try {
         ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster();
         multicaster.removeApplicationListener((ApplicationListener<?>) bean);
         multicaster.removeApplicationListenerBean(beanName);
      }
      catch (IllegalStateException ex) {
         // ApplicationEventMulticaster not initialized yet - no need to remove a listener
      }
   }
}

以上就是ApplicationListenerDetector監(jiān)聽器判斷demo的詳細內(nèi)容,更多關(guān)于ApplicationListenerDetector監(jiān)聽器的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論