如果你需要在你的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. VS2008 error PRJ0002 : 错误的结果 31 (从“C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\rc.exe”返回)。

    解决方案,选择属性->配置属性->清单工具->输入和输出->嵌入清单,把是改成否

  2. Jquery设置完颜色后hover不生效的解决办法

    执行完代码后发现写在样式表中的hover效果失效,改了好几遍差点重新写函数,后来发现很简单,是优先级的问题,css()中的内容覆盖了之前的样式 只需要在样式后写!important即可解决! .fil ...

  3. SSH框架与SSI框架的区别

    2013-03-04 13:45 1427人阅读 评论(0) 收藏 举报 一.SSH 整个配置如下图所示: 1. <?xml version="1.0" encoding=& ...

  4. Navicat导入json文件到数据库

    最近做小程序商城系统,物流管理这块需要存储国际和中国的物流地址. 所以,天哪,地址那么的多!!!! www.baidu.com,搜索大佬是如何做的.有的是通过访问阿里云快递物流api接口获取数据存入数 ...

  5. Django(十五)模板详解:模板标签、过滤器、模板注释、模板继承、html转义

    一.模板的基础配置及使用 [参考]https://docs.djangoproject.com/zh-hans/3.0/topics/templates/ 作为Web框架,Django提供了模板,用于 ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮组

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. thinkphp的增删改查命令 - (mysql-thinkphp) (4)

    方法1,在namespace下面加2行 use think\Controller; use think\Db; 1.查询所有结果 $res = Db::query("select * fro ...

  8. 新闻网大数据实时分析可视化系统项目——18、Spark SQL快速离线数据分析

    1.Spark SQL概述 1)Spark SQL是Spark核心功能的一部分,是在2014年4月份Spark1.0版本时发布的. 2)Spark SQL可以直接运行SQL或者HiveQL语句 3)B ...

  9. R 《回归分析与线性统计模型》page119,4.2

    rm(list = ls()) library(openxlsx) library(MASS) data = read.xlsx("xiti_4.xlsx",sheet = 2) ...

  10. 034、Java中自增之++在前面的写法

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...