有时候项目会有这样的需求:在 springboot 项目启动完成之后,需要加载一些数据
最先想到的方法就是通过 ApplicationRunner
去做:
@Component
public class TestApplicationRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("TestApplicationRunner method will be execute when the project started");
}
}
除了 ApplicationRunner
这种方式去做之外,还可以通过 CommandLineRunner
去做:
@Component
public