Springboot--事件监听

Posted dachengcheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Springboot--事件监听相关的知识,希望对你有一定的参考价值。

 

1 通过SpringApplication发布事件

技术分享图片

 

 2 springboot交给 SimpleApplicationEventMulticaster进行处理

  2.1会从缓存中寻找该事件的监听者。其中cachekey是由事件和sourceType确定的类似于这样 "ListenerCacheKey [eventType = org.springframework.boot.context.event.ApplicationReadyEvent, sourceType = class org.springframework.boot.SpringApplication]"

  补充:springboot会在发布事件的时候,遍历所有的listener,然后将监听本事件的listener缓存起来,后面再次发布该事件的时候可以从缓存中取

  技术分享图片

  2.2 将监听该事件的listner缓存起来。

技术分享图片

 

3 循环调用监听者相关接口,完成事件通知 

技术分享图片

 

 

 学习springboot事件监听源码,如有不对请大家多多指教

 

以上是关于Springboot--事件监听的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot入门之事件监听

Springboot--事件监听

SpringBoot监听器ApplicationListener的使用-监听ApplicationReadyEvent事件

springboot~ EventListener事件监听的使用

SpringBoot加载应用事件监听器

SpringBoot加载应用事件监听器