在项目启动时,有时需要加载一些特定的静态文件或者执行某些特定的方法,springboot为我们提供了两种开机启动的接口
- CommandLineRunner
- ApplicationRunner
CommandLineRunner实现
@Component
public class MyCommand implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("执行我的代码。。。");
}
}
执行结果
image.pngApplicationRunner实现
@Component
public class MyCommand implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("执行application。。。");
}
}
执行结果
image.png
网友评论