SpringFramework事件与监听机制(@EventListener)

本文详细介绍了Spring Framework中@EventListener的初始化工作,包括EventListenerMethodProcessor和DefaultEventListenerFactory的角色。在Spring Boot 2.0.2.RELEASE和Spring Framework 5.0.6.RELEASE中,@EventListener注解的方法如何转换为ApplicationListener并融入事件监听机制。文章还讨论了ApplicationListenerMethodAdapter的结构和事件匹配过程。
摘要由CSDN通过智能技术生成

SpringBoot版本:2.0.2.RELEASE
SpringFramework版本:5.0.6.RELEASE


之前的“SpringFramework事件与监听机制”系列文章已经从接口层面上介绍了事件、监听器和发布器。其实使用@EventListener也能达到ApplicationLister接口的效果,根据我们对spring的认识,它们不会轻易放过代码重用的机会,那么@EventListener标注的使用,是否基于SpringFramework事件与监听机制呢?本文旨在探讨@EventListener是如何工作的,所以@EventListener使用上的细节,请在官网或者其实阅读资料查询。

@EventListener的初始化工作

EventListenerMethodProcessor与DefaultEventListenerFactory是两个重要的类,它们在AnnotationConfigUtils#registerAnnotationConfigProcessors方法里被注册到BeanDefinitionRegistry去了。
在SpringBoot程序的程动过程中,在构造AnnotationConfigApplicationContext的时候会调用此方法。它的方法调用链如下:

SpringApplication.run SpringApplication.createApplicationContext AnnotationConfigApplicationContext() <
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值