版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Cainiao111112/article/details/83213404
场景:在使用spring boot构建项目时,我们通常有一些需要预先加载的数据。
使用:我们可以通过实现CommandLineRunner接口,重写run方法。
:当存在多个需要加载的数据类时,我们可以使用@Order进行排序。
/**
* 启动时预加载
*
* @author aku
*/
@Component
public class StarterTest implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("启动预加载");
}
}