springboot Interface: CommandLineRunner

springBoot Interface: CommandLineRunner

First, the role:

When building the project using SpringBoot, we usually have some pre-loaded data. So SpringBoot provides a simple way to achieve -CommandLineRunner.

Second, use:

CommandLineRunner is an interface, we need time, just implement the interface on the line. If more than one add data exists, we can also use @Order annotation sort.

@Component
@Order(value = 2)
public class MyStartupRunner1 implements CommandLineRunner{
@Override
public void run(String... strings) throws Exception {
    System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作 MyStartupRunner1 order 2 <<<<<<<<<<<<<");
    }
}

@Component
@Order(value = 1)
public class MyStartupRunner2 implements CommandLineRunner {
@Override
public void run(String... strings) throws Exception {
    System.out.println(">>>>>>>>>>>>>>>服务启动执行,执行加载数据等操作 MyStartupRunner2 order 1 <<<<<<<<<<<<<");
    }
}

Third, show:

Guess you like

Origin www.cnblogs.com/xujie09/p/11261542.html