Spring項目啓動時,若是須要初始化資源,能夠實現ApplicationRunner或者CommandLineRunner,而且可使用註解@Order指定他們的運行順序。
java
示例代碼:https://github.com/rickding/HelloJava/tree/master/HelloRunnergit
3個類文件:github
RunnerApplication.java實現SpringBootApplication主程序:ide
HelloApplicationRunner.java實現ApplicationRunner:spa
HelloCommandLineRunner.java實現CommandLineRunner,而且指定@Order(1):.net
輸出日誌:3d