我们使用SpringBoot构建项目时,经常会经常会预先加载一些数据,这时就可以使用CommandLineRunner接口。
当有多个这样的类来加载数据时,@Order注解中的数字代表加载的顺序,数字越小的先加载。
@Component
@Order(1)
public class MyStartupRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("预先加载的数据 ");
}
}
最后
以上就是感性饼干最近收集整理的关于SpringBoot之CommandLineRunner的全部内容,更多相关SpringBoot之CommandLineRunner内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复