SpringBoot入門(8)- SpringBoot 事件監聽
阿新 • • 發佈:2018-12-12
- 事件流程:
- 自定義事件,一般繼承ApplicationEvent抽象類
- 定義事件監聽器,一般實現ApplicationListener介面,註冊監聽器到spring容器中context.addListeners(listerner)
- 釋出事件 context.publishEvent(event);
- 監聽器註冊方式
- Context.addListerners(listerner)
- @compent註解在監聽器類上,納入spring容器管理
- 通過配置檔案配置項,context.listener.classes=監聽器全類名
-
- 定義一個納入spring容器管理的類,介面的引數必須和監聽器的引數保持一致,在介面上添加註解
- 定義一個納入spring容器管理的類,介面的引數必須和監聽器的引數保持一致,在介面上添加註解
- 深入瞭解c和d實現方式
- DelegatingApplicationListener中存在配置屬性context. .classes,載入生成
- D的實現EventListenerPocessor介面,內部實現也是新增EventListener到context
- springBoot內部定義好的event
- spring.boot.event下的事件類