order的规则:

order的值越小,优先级越高
order如果不标注数字,默认最低优先级,因为其默认值是int最大值
该注解等同于实现Ordered接口getOrder方法,并返回数字。

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Documented
public @interface Order {

/**
* The order value.
* <p>Default is {@link Ordered#LOWEST_PRECEDENCE}.
* @see Ordered#getOrder()
*/
int value() default Ordered.LOWEST_PRECEDENCE;

}

int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
@Aspect
@Component
public class DataSourceAspect implements Ordered {

@Override
public int getOrder() {
return 1;
}

}
见下:

OrderRunner1.java

@Component
@Order(1)
public class OrderRunner1 implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
System.out.println("The OrderRunner1 start to initialize ...");
}
}
 OrderRunner2.java

@Component
@Order(2)
public class OrderRunner2 implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
System.out.println("The OrderRunner2 start to initialize ...");
}
}
 Runner.java

@Component
public class Runner implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
System.out.println("The Runner start to initialize ...");
}
}
@SpringBootApplication
public class CommandLineRunnerApplication {

public static void main(String[] args) {
System.out.println("The service to start.");
SpringApplication.run(CommandLineRunnerApplication.class, args);
System.out.println("The service has started.");
}
}

它们的启动日志:

The service to start.
...
...
The OrderRunner1 start to initialize ...
The OrderRunner2 start to initialize ...
The Runner start to initialize ...
The service has started.
 
---------------------
作者:jiangxwa
来源:CSDN
原文:https://blog.csdn.net/jiangxwa/article/details/87892577
版权声明:本文为博主原创文章,转载请附上博文链接!

最新文章

  1. 如何用C#+WinRAR 实现压缩 分类:
  2. Java:基于LinkedList实现栈和队列
  3. &lt;记录学习&gt;京东页面最后一天HTML以及css遇到的问题
  4. JavaWeb学习总结-07 Filter 学习和使用
  5. nohup启动java命令导致dubbo无法注册
  6. jQuery 选择器语法
  7. [Effective JavaScript 笔记]第30条:理解prototype、getPrototypeOf和__ptoto__之间的不同
  8. Strassen算法
  9. 实现带有getMin的栈
  10. LeetCode_Swap Nodes in Pairs
  11. SQL Server 2008 忘记sa密码的解决办法
  12. C#用正则表达式 获取网页源代码标签的属性或值
  13. java基础(九章)
  14. 深入浅出AQS之条件队列
  15. Spring Boot 2.0 教程 | 配置 Undertow 容器
  16. Java中使用MongoDB
  17. Html5游戏开发-图形与动画(一)
  18. windows版 Java调用人脸识别离线sdk
  19. You Don&#39;t Know JS: this &amp; Object Prototypes( 第5章 Prototypes)
  20. list的四种遍历方式

热门文章

  1. Time Series_1_BRKA Case
  2. leetcode713 Subarray Product Less Than K
  3. Java中很少用的CopyOnWriteArrayList
  4. PCA算法提取人脸识别特征脸(降噪)
  5. 2-10 就业课(2.0)-oozie:8、定时任务的执行
  6. css的艺术
  7. Day5 - F - 食物链 POJ - 1182
  8. 016、MySQL取本年第一季度开始日期
  9. centos7下安装ansible
  10. 获取选中行中的数据提取并且保存到txt