zoukankan      html  css  js  c++  java
  • 【SpringBoot】零碎

     

    启动后自动执行任务

    实现CommandLineRunner接口,实现其中的run(String... args) 方法。

    如果存在多个实现类,则指定 @Order注解决定顺序

    @SpringBootApplication
    @Order(2)
    public class Application implements CommandLineRunner {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
        @Override
        public void run(String... args) throws Exception {
            System.out.println("Application run..........");
        }
    }
    
    ///////////////////////////////////////////////////
    
    @Component
    @Order(1)
    public class Service1  implements CommandLineRunner {
        @Override
        public void run(String... args) throws Exception {
            System.out.println("Service1 run...............");
        }
    }
    
    
    ///////////////////////////////////////////////////
    
    @Component
    @Order(3)
    public class Service3 implements CommandLineRunner {
        @Override
        public void run(String... args) throws Exception {
            System.out.println("Service3 run..........");
        }
    }
    View Code

    执行效果:

  • 相关阅读:
    python工具类 md5
    python 线程池, 进程池
    scrapydweb 安装部署
    python 协程
    jquery
    scrapyd 设置访问密码
    pat 乙级1033 旧键盘打字(20)
    1459 迷宫游戏(51NOD)
    python之禅
    Jzzhu and Cities ----CodeForces
  • 原文地址:https://www.cnblogs.com/clarino/p/15496160.html
Copyright © 2011-2022 走看看