如果你需要在你的SpringBoot启动完成之后实现一些功能,那么可以通过创建class实现ApplicationRunner和CommandLineRunner来完成:

@Component
public class ApplicationRunnerTest implements ApplicationRunner { @Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("========>> ApplicationRunner.run");
for (String sourceArg : args.getSourceArgs()) {
System.out.println(sourceArg);
}
for (String optionName : args.getOptionNames()) {
System.out.println(optionName + " = " + args.getOptionValues(optionName));
}
System.out.println("========>> End");
}
}
@Component
public class CommandLineRunnerTest implements CommandLineRunner { @Override
public void run(String... args) throws Exception {
System.out.println("========>> CommandLineRunner.run");
for (String sourceArg : args) {
System.out.println(sourceArg);
}
System.out.println("========>> End");
}
}

如果你定义了多个ApplicationRunner或者CommandLineRunner,并想要控制他们执行的先后顺序,可以让你定义的class实现org.springframework.core.Ordered接口,或者直接注解@Order

SpringBoot的ApplicationRunner和CommandLineRunner的更多相关文章

  1. 剖析ApplicationRunner、CommandLineRunner

    需求:SpringBoot项目启动成功后执行某方法 方案:在spring-boot中提供了两种Runner接口:ApplicationRunner和CommandLineRunner,编写自己的类实现 ...

  2. SpringBoot扩展点之二:ApplicationRunner和CommandLineRunner的扩展

    CommandLineRunner并不是Spring框架原有的概念,它属于SpringBoot应用特定的回调扩展接口: public interface CommandLineRunner { /** ...

  3. SpringBoot的ApplicationRunner

    Article1 在开发中可能会有这样的情景.需要在容器启动的时候执行一些内容.比如读取配置文件,数据库连接之类的.SpringBoot给我们提供了两个接口来帮助我们实现这种需求.这两个接口分别为Co ...

  4. SpringBoot之ApplicationRunner接口和@Order注解

    我们在开发中可能会有这样的情景.需要在容器启动的时候执行一些内容.比如读取配置文件,数据库连接之类的.SpringBoot给我们提供了ApplicationRunner接口来帮助我们实现这种需求.该接 ...

  5. springboot应用中使用CommandLineRunner

    在springboot应用中,存在这样的使用场景,在springboot ioc容器创建好之后根据业务需求先执行一些操作,springboot提供了两个接口可以实现该功能: CommandLineRu ...

  6. SpringBoot-容器启动的时候执行一些内容

    SpringBoot的ApplicationRunner.CommandLineRunner 场景: 在开发中可能会有这样的情景.需要在容器启动的时候执行一些内容.比如读取配置文件,数据库连接之类的. ...

  7. Spring Boot 2 - 使用CommandLineRunner与ApplicationRunner

    本篇文章我们将探讨CommandLineRunner和ApplicationRunner的使用. 在阅读本篇文章之前,你可以新建一个工程,写一些关于本篇内容代码,这样会加深你对本文内容的理解,关于如何 ...

  8. 使用CommandLineRunner或ApplicationRunner接口创建bean

    在spring boot应用中,我们可以在程序启动之前执行任何任务.为了达到这个目的,我们需要使用CommandLineRunner或ApplicationRunner接口创建bean,spring ...

  9. Spring Boot 启动加载数据 CommandLineRunner

    实际应用中,我们会有在项目服务启动的时候就去加载一些数据或做一些事情这样的需求. 为了解决这样的问题,Spring Boot 为我们提供了一个方法,通过实现接口 CommandLineRunner 来 ...

随机推荐

  1. Java 8 Stream 的终极技巧——Collectors 操作

    1. 前言 昨天在 Collection移除元素操作 相关的文章中提到了 Collectors .相信很多同学对这个比较感兴趣,那我们今天就来研究一下 Collectors . 2. Collecto ...

  2. docker-compose 修改zabbix images 添加微信报警插件 时间同步 中文乱码 添加grafana美化zabbix

    我们先来看一下我们要修改得  zabbix.yaml           github   https://github.com/bboysoulcn/awesome-dockercompose ve ...

  3. P1076 Wifi密码

    P1076 Wifi密码 转跳点:

  4. P1079 延迟的回文数

    P1079 延迟的回文数 转跳点:

  5. C# Chart 点击获取当前点击坐标和Series

    C# Chart 点击获取当前点击坐标和Series https://blog.csdn.net/wumuzhizi/article/details/47168989 2015年07月31日 13:5 ...

  6. git下载安装、配置及idea初始化

    安装 wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.19.0.tar.gz git 安装依赖 yum -y insta ...

  7. 065、Java面向对象之定义一个Book类,在主类中使用Book类

    01.代码如下: package TIANPAN; class Book { // 定义一个新的类 String title; // 书的名字 double price; // 书的价格 public ...

  8. awk&sed

    sed BRE       awk  ERE sed 不能采用?   awk可以 sed 在匹配的任何时候可以用^,$ awk必须除了在行头和行尾 其他地方必须转义

  9. Nifi简介及核心概念整理

    简介 Apache NiFi 是一个易于使用.功能强大而且可靠的数据拉取.数据处理和分发系统,用于自动化管理系统间的数据流. 它支持高度可配置的指示图的数据路由.转换和系统中介逻辑,支持从多种数据源动 ...

  10. Git如何将本地test分支设置跟踪origin/test分支

    前提条件: 有一个远程仓库其中只有一个master分支,然后我把它clone到本地 1.新建一个本地分支test, 2.然后把它push到远程仓库(git push origin test) 3.本地 ...