ApplicationRunner
实现ApplicationRunner接口,并重写run函数,可以实现springboot项目启动完成之后的回调
public class MyApplicationRunner implements ApplicationRunner {
public void run(ApplicationArguments args) throws Exception {
//something to do
}
}
CommandLineRunner
实现CommandLineRunner接口,并重写run函数,可以实现springboot项目启动完成之后的回调
public class MyCommandLineRunner implements CommandLineRunner {
public void run(String... args) throws Exception {
}
}
@PreDestroy
采用@PreDestroy
注释可以实现springboot项目停止之后的钩子回调,运用实例如下所示:
public class MyPreDestroy {
public void myPreDestroy() {
}
}