一:启动时完成数据加载等需求
实现ApplicationListener接口,官方文档截图:
ApplicationListener接口的泛型类可以使用
ApplicationStartedEvent
和ApplicationReadyEvent
应用监听器事件执行先后顺序如下:
- ApplicationStartingEvent
- ApplicationEnvironmentPreparedEvent
- ApplicationPreparedEvent
- ApplicationStartedEvent
- ApplicationReadyEvent
- ApplicationFailedEvent
实现CommandLineRunner和ApplicationRunner完成启动加载数据
二. 关闭时完成某些操作
- 实现ApplicationListener
- 实现DisposableBean接口
本文由 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为: 2020/05/18 03:49