• spring boot启动加载项CommandLineRunner


    spring boot启动加载项CommandLineRunner

    在使用SpringBoot构建项目时,我们通常有一些预先数据的加载。那么SpringBoot提供了一个简单的方式来实现–CommandLineRunner。

    CommandLineRunner是一个接口,我们需要时,只需实现该接口就行。如果存在多个加载的数据,我们也可以使用@Order注解来排序。 
    案例: 
    分别定义了一个数据加载类MyStartupRunner1,排序为2;以及另一个数据加载类MyStartupRunner2,排序为1。

     1 @Component
     2 @Order(value = 2)
     3 public class MyStartupRunner1 implements CommandLineRunner{
     4 @Override
     5 public void run(String... args) throws Exception {
     6     System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作 MyStartupRunner1 order 2 <<<<<<<<<<<<<");
     7     }
     8 }
     9 
    10 @Component
    11 @Order(value = 1)
    12 public class MyStartupRunner2 implements CommandLineRunner {
    13 @Override
    14 public void run(String... args) throws Exception {
    15     System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作 MyStartupRunner2 order 1 <<<<<<<<<<<<<");
    16     }
    17 }
  • 相关阅读:
    函数表达式
    BOM
    让超出容器高度的内容滚动显示但不出现滚动条
    插件书写示例
    php中redis的安装
    日常工作bug总结
    pip freeze requirements.txt命令迁移模块
    Django18-中间件和cache实现限制用户访问频率
    Django17-文件上传下载
    Django16-cache缓存
  • 原文地址:https://www.cnblogs.com/heqiyoujing/p/9437434.html
Copyright © 2020-2023  润新知