1. 程式人生 > >CommandLineRunner 預載入

CommandLineRunner 預載入

場景:在使用spring boot構建專案時,我們通常有一些需要預先載入的資料。

使用:我們可以通過實現CommandLineRunner介面,重寫run方法。

        :當存在多個需要載入的資料類時,我們可以使用@Order進行排序。

/**
 * 啟動時預載入
 * 
 * @author aku
 */
@Component
public class StarterTest implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        System.out.println("啟動預載入");
    }

}