开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第31天,点击查看活动详情
1.新建Runner包
2.新增BootApplicationRunner和BootCommandLineRunner类
BootApplicationRunner类:
@Slf4j
@Component
public class BootApplicationRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("this is BootApplicationRunner");
}
}
BootCommandLineRunner类:
@Slf4j
@Component
public class BootCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
log.info("this is commandLineRunner");
}
}
代码说明:
- @Component:设置成组件
3.启动项目
可以看到,BootApplicatioin优先级高于BootCommandLineRunner
4.设置优先级
代码说明:
- @Order(1):order值越小,越早执行