Development time required to perform some initialization function after the start of the project, soringBoot can be added to a model and implement CommandLineRunner interface code that implements the function on the run method implemented in
package org.springboot.sample.runner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component //作为bean加入spring
@Order(value=2)//多个启动任务的执行顺序
public class MyStartupRunner1 implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println(">>>>>>>>>>>>>>>服务启动执行 2222 <<<<<<<<<<<<<");
}
}
Reproduced in: https: //www.jianshu.com/p/4495f0663e25