启动系统任务

HeJin小于 1 分钟Spring全家桶SpringBoot精讲细讲

实现了CommandLineRunnerApplicationRunner这两个接口的类会在系统启动之后自动调用run方法。

Redis预热、系统检查等

CommandLineRunner

@Order(1)
@Component
public class CommandRunnerOne implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        System.out.println("CommandLineRunner start...");
    }
}

ApplicationRunner

@Order(2)
@Component
public class CommandRunnerTwo implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("ApplicationRunner start...");
    }
}
image-20210511120600276
image-20210511120600276