spring boot 系统启动运行的类 MyCommandLineRunner

来源:互联网 发布:信用卡 对比.知乎 编辑:程序博客网 时间:2024/06/07 07:09
@Component@Order(value=1)public class MyCommandLineRunner implements CommandLineRunner {    @Override    public void run(String... args) throws Exception {        System.out.println("初始化完毕......" + new Date());    }}
启动时,还可以调用其他类进行初始化一些动作
@Component@Order(value=1)public class MyCommandLineRunner implements CommandLineRunner {    @Autowired    StatService statService;    @Autowired    RepairService repairService;    @Autowired    OilTimesService oilTimesService;    @Override    public void run(String... args) throws Exception {        System.out.println("========系统启动...开始执行=============");        statService.dis();        statService.stat();        repairService.repairDis(null, null, null, null);        oilTimesService.timesfilter(null);    }}