Spring加载资源文件目前了解三种,

  1. @PostConstruct在Context加载完成之后加载。在创建各个Bean对象之前加载。

  2. 实现ApplicationRunnerrun方法,Bean加载完成之后加载,优先于CommandLineRunner执行。

@Component
@Order(2)
public class ApplicationRunnerTest implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("我略迟于CommandLineRunner执行!!!");
}
}

如果对于顺序没有要求,并且使用的是jdk1.8那么可以采用下面的写法

@Bean
public ApplicationRunner applicationRunner(){
return args -> System.out.println("我优先于CommandLineRunner执行!!!");
}
  1. 实现CommandLineRunnerrun方法,Bean加载完成之后加载,ApplicationRunner之后执行,可以通过@Order(order)调整加载顺序。

@Component
@Order(1)
public class CommandLineRunnerTest implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("我优先于ApplicationRunner执行!!!");
}
}

如果对于顺序没有要求,并且使用的是jdk1.8那么可以采用下面的写法

@Bean
public CommandLineRunner commandLineRunner(){
return args -> System.out.println("我略迟于ApplicationRunner执行!!!");
}

最新文章

  1. iptables中文介绍 、基本使用操作命令(转)
  2. 【转】android中ListView的定位:使用setSelectionFromTop实现ListView的position的保持
  3. JavaScript实现快速排序
  4. Docker实践(1)—入门
  5. Matlab生成动态链接库供C#调用
  6. C++学习笔记:指向函数的指针
  7. Application.EnableVisualStyles();
  8. 卸载安装失败的sqlserver2008 R2
  9. SQL也能玩递归
  10. libvirt C-API
  11. Quartz.NET学习系列
  12. HDU1102(最小生成树Kruskal算法)
  13. js实现html转pdf+html2canvas.js截图不全的问题
  14. [LeetCode] Boundary of Binary Tree 二叉树的边界
  15. go 学习第一个hello world 遇到的问题
  16. 7#Java基本语句语法
  17. 【HDU - 4349】Xiao Ming's Hope
  18. Dynamics CRM 2016/365 窗体中添加按钮
  19. PHP MYSQL 临时表的使用
  20. 分布式强化学习基础概念(Distributional RL )

热门文章

  1. noi.ac #536 打地鼠
  2. 简单快捷的方式从vps下载文件
  3. Java实验课:命令行参数是什么?
  4. Spring Boot教程(四十一)LDAP来管理用户信息(1)
  5. hadoop-httpfs
  6. React 番外篇
  7. git *** Please tell me who you are.错误
  8. slub分配object
  9. vue文件流转换成pdf预览(pdf.js+iframe)
  10. EDM数据营销之电商篇| 六大事务性邮件,环环相扣打造极致用户体验!