重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
一:启动时完成数据加载等需求
实现ApplicationListener接口,官方文档截图:
ApplicationListener接口的泛型类可以使用ApplicationStartedEvent和ApplicationReadyEvent
应用监听器事件执行先后顺序如下:
实现CommandLineRunner和ApplicationRunner完成启动加载数据
二:关闭时完成某些操作
实现ApplicationListener
实现DisposableBean接口
三、spring boot应用关闭操作(Linux/unix/ubuntu环境下进行)
A、非安全验证
1、项目pom.xml添加如下依赖包:
org.springframework.boot spring-boot-starter-actuator