SpringBoot学习笔记(三)——启动后运行特定代码

想要在项目启动后自动执行特定代码可以通过实现ApplicationRunner或CommandLineRunner,并重写其run()方法

如果有多个启动后自动执行的代码块,想要指定执行顺序执行,可以使用@Order注解,如上图绿框标注,数字越小,优先级越高

测试结果如图:

猜你喜欢

转载自blog.csdn.net/Peacock__/article/details/87882871