浅谈 @EventListener 和 @TransactionalEventListener
前言
spring 有一个事件传播机制,可以较为方便地实现一个简单的广播模型
一般使用 ApplicationEventPublisher
(org.springframework.context.ApplicationEventPublisher) 来发布一个事件,然后使用 @EventListener
或者 @TransactionalEventListener
标记的方法来接收指定的事件
这样做有什么好处呢?一方面是解耦,另一方面提高可拓展性