详解Springboot应用启动以及关闭时完成某些操作-创新互联
一:启动时完成数据加载等需求
实现ApplicationListener接口,官方文档截图:
ApplicationListener接口的泛型类可以使用ApplicationStartedEvent和ApplicationReadyEvent
应用监听器事件执行先后顺序如下:
- ApplicationStartingEvent
- ApplicationEnvironmentPreparedEvent
- ApplicationPreparedEvent
- ApplicationStartedEvent
- ApplicationReadyEvent
- ApplicationFailedEvent
实现CommandLineRunner和ApplicationRunner完成启动加载数据
二:关闭时完成某些操作
实现ApplicationListener
实现DisposableBean接口
三、spring boot应用关闭操作(Linux/unix/ubuntu环境下进行)
A、非安全验证
1、项目pom.xml添加如下依赖包:
org.springframework.boot spring-boot-starter-actuator
文章名称:详解Springboot应用启动以及关闭时完成某些操作-创新互联
URL网址:http://pcwzsj.com/article/dceiih.html