1. 事件监听步骤:
1.自定义事件,一般是继承ApplicationEvent抽象类
2.定义事件监听器,一般是实现ApplicationListener接口
3.启动的时候需要把监听器加入到spring容器中
4.发布事件:使用ApplicationContext 的 ApplicationEventPublisher接口的publishEvent方法
2. 配置监听器方法:
1.使用context.addApplicationListener方法
2.@component类型注解
3.配置文件配置 context.listener.classes=com.zxf.learn10.MyApplicationListener(详细内容参照DelegatingApplicationListener)
4. 使用@EventListener注解,在方法上面加入@EventListener注解,且该类需要纳入spring容器中管理(详细参照EventListenerMethodProcessor)
spring 自带有许多时间 在 context.event 包下, spring springboot都有。
5.META-INF/spring.factories配置org.springframework.context.ApplicationListener=