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