SpringBoot开启启动

60 阅读1分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第31天,点击查看活动详情

1.新建Runner包

image.png

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");
    }
}

image.png 代码说明:

  • @Component:设置成组件

3.启动项目

可以看到,BootApplicatioin优先级高于BootCommandLineRunner image.png

4.设置优先级

image.png 代码说明:

  • @Order(1):order值越小,越早执行 image.png