我们在开发中可能会有这样的情景。需要在容器启动的时候执行一些内容。比如读取配置文件,数据库连接之类的。SpringBoot给我们提供了ApplicationRunner接口来帮助我们实现这种需求。该接口执行时机为容器启动完成的时候。

ApplicationRunner接口

具体代码如下:

@Component
@Order(1)
public class TestImplApplicationRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("这个是测试ApplicationRunner接口1"); }
}

@Order注解

如果有多个实现类,而你需要他们按一定顺序执行的话,可以在实现类上加上@Order注解。@Order(value=整数值)。SpringBoot会按照@Order中的value值从小到大依次执行。

@Component
@Order(2)
public class TestImplApplicationRunner2 implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("这个是测试ApplicationRunner接口2"); }
}

在加上@Order注解后,执行顺序会根据数字从小到大执行

最新文章

  1. 从SQL的视角用powershell
  2. sql 多行合一行
  3. windows下php连接sqlserver2008
  4. php+curl上传文件
  5. CentOS下搭建SVN服务器
  6. 2016年11月10日 星期四 --出埃及记 Exodus 20:1
  7. Excel中连接函数CONCATENATE()
  8. Restrict each user to a single session in window server 2008 R2 or 2012
  9. C++指针和引用
  10. node.js操作mongoDB数据库
  11. PHP Cookie学习
  12. Python 对Twitter中指定话题的被转载Tweet数量的频谱分析
  13. mongo查询系统
  14. js 过滤敏感词 ,可将带有标点符号的敏感词过滤掉
  15. 关于setTimeout的面试题
  16. 对于zuul服务网关框架资料整理
  17. liblensfun 在 mingw 上编译时遇到的奇怪问题
  18. java中Base64的加密工具封装
  19. SQL Server 4
  20. JAVAWEB eclipse开启服务器时,filter出现找不到的问题时

热门文章

  1. 微信公众号 唤醒手机导航APP 一看就懂 复制即用
  2. Linux学习_菜鸟教程_2
  3. 升级添加到现有iOS Xcode项目的Flutter
  4. json中含有换行符'\r','\n'的处理
  5. 微信小程序点击图片放大
  6. 79.纯 CSS 创作单元素麦当劳金拱门 Logo(原文)
  7. axios中请求传值方式
  8. Webpack实战(六):如何优雅地运用样式CSS预处理
  9. JS ES6补充
  10. [组合数学][多项式][拉格朗日插值]count