1. 事件流程:
    1. 自定义事件,一般继承ApplicationEvent抽象类
    2. 定义事件监听器,一般实现ApplicationListener接口,注册监听器到spring容器中context.addListeners(listerner)
    3. 发布事件 context.publishEvent(event);
  2. 监听器注册方式
    1. Context.addListerners(listerner)
    2. @compent注解在监听器类上,纳入spring容器管理
    3. 通过配置文件配置项,context.listener.classes=监听器全类名

SpringBoot入门(8)- SpringBoot 事件监听

    1. 定义一个纳入spring容器管理的类,接口的参数必须和监听器的参数保持一致,在接口上添加注解@EventListener;接口的参数必须存在,类型任意,如果指定具体事件类型,则只监听指定事件的监听(推荐使用),需要创监听器的实现类,由注解@EventListener创建完成

SpringBoot入门(8)- SpringBoot 事件监听

 

  1. 深入了解c和d实现方式
    1. DelegatingApplicationListener中存在配置属性context.       .classes,加载生成
    2. D的实现EventListenerPocessor接口,内部实现也是添加EventListener到context

 

  1. springBoot内部定义好的event
    1. spring.boot.event下的事件类

相关文章: