Spring项目启动时,ApplicationRunner和CommandLineRunner的用法

Spring项目启动时,若是须要初始化资源,能够实现ApplicationRunner或者CommandLineRunner,而且可使用注解@Order指定他们的运行顺序。
java


示例代码:https://github.com/rickding/HelloJava/tree/master/HelloRunnergit

3个类文件:github

image.png


RunnerApplication.java实现SpringBootApplication主程序:ide

image.png


HelloApplicationRunner.java实现ApplicationRunner:spa

image.png


HelloCommandLineRunner.java实现CommandLineRunner,而且指定@Order(1):.net

image.png


输出日志:3d

image.png


参考文章:http://www.javashuo.com/article/p-qcejhsfi-bx.html日志

相关文章
相关标签/搜索