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

    执行效果:

  • 相关阅读:
    lea
    DIV指令
    html基础
    浮点计算结果误差,以及解决方法
    java的threadLocal类
    java多线程基础总结
    sql反模式读书笔记 (持续更新)
    pdb 调试初步
    面向对象设计原则与总结 (持续更新)
    @servcie注解基本用法
  • 原文地址:https://www.cnblogs.com/clarino/p/15496160.html
Copyright © 2011-2022 走看看