ApplicationListenerDetector監(jiān)聽器判斷demo
Bean實(shí)例化之后
判斷Bean是否是監(jiān)聽器,如果是監(jiān)聽器就將當(dāng)前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銷毀之前
如果當(dāng)前Bean是監(jiān)聽器,就將當(dāng)前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的詳細(xì)內(nèi)容,更多關(guān)于ApplicationListenerDetector監(jiān)聽器的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Spring Boot 配置 Quartz 定時(shí)任務(wù)的方法
這篇文章主要介紹了Spring Boot 配置 Quartz 定時(shí)任務(wù)的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09
SpringBoot如何統(tǒng)一處理返回結(jié)果和異常情況
這篇文章主要介紹了SpringBoot如何統(tǒng)一處理返回結(jié)果和異常情況問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
maven項(xiàng)目test執(zhí)行main找不到資源文件的問題及解決
這篇文章主要介紹了maven項(xiàng)目test執(zhí)行main找不到資源文件的問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
當(dāng)mybatis返回值遇見內(nèi)部類的問題
這篇文章主要介紹了當(dāng)mybatis返回值遇見內(nèi)部類的問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12
SpringBoot中支持Https協(xié)議的實(shí)現(xiàn)
本文主要介紹了SpringBoot中支持Https協(xié)議的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01
Java調(diào)用Zookeeper的實(shí)現(xiàn)步驟
本文主要介紹了Java調(diào)用Zookeeper的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
SpringMVC Idea 搭建 部署war的詳細(xì)過程
本文介紹了如何在IntelliJ IDEA中使用Maven模板創(chuàng)建一個(gè)Web項(xiàng)目,并詳細(xì)說明了如何配置web.xml、創(chuàng)建springmvc-servlet.xml和application.properties文件,以及如何使用Maven打包生成WAR文件并部署到Tomcat服務(wù)器,感興趣的朋友跟隨小編一起看看吧2025-01-01

