Spring监听的另一种写法

@EventListener在哪里解析的?

org.springframework.beans.factory.support.DefaultListableBeanFactory#preInstantiateSingletons

 

 org.springframework.context.event.EventListenerMethodProcessor#processBean

遍历所有bean里面的所有加了@EventListener注解的方法

找到后开始遍历,这里也是个适配器模式

 

 

在spring容器手动加了一个ApplicationListenerMethodAdapter,供后续使用

执行目标方法的时候,这个监听器这正是我们注册的那个适配器 

最后反射进到监听的目标方法中

猜你喜欢

转载自blog.csdn.net/u012222011/article/details/129985264