博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
@Order 注解
阅读量:3959 次
发布时间:2019-05-24

本文共 1253 字,大约阅读时间需要 4 分钟。

@Order 注解

@Order注解主要用来控制配置类的加载顺序

示例代码:

package com.runlion.tms.admin.constant;public class AService {}package com.runlion.tms.admin.constant;public class BService {}
package com.runlion.tms.admin.constant;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.core.annotation.Order;@Configuration@Order(2)public class AConfig {  @Bean  public AService AService() {    System.out.println("AService 加载了");    return new AService();  }}package com.runlion.tms.admin.constant;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.core.annotation.Order;@Configuration@Order(1)public class BConfig {  @Bean  public BService bService() {    System.out.println("BService 加载了");    return new BService();  }}

测试类:

package com.runlion.tms.admin.constant;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class OrderMain {  public static void main(String[] args) {    AnnotationConfigApplicationContext context =        new AnnotationConfigApplicationContext("com.runlion.tms.admin.constant");  }}

输出结果:

BService 加载了
AService 加载了

因为BService 的@Order(1),所以先打印出来

转载地址:http://soazi.baihongyu.com/

你可能感兴趣的文章
POJ2838,Sliding Window(单调队列)
查看>>
牛客练习赛50,B tokitsukaze and Hash Table(STL+输入输出挂)
查看>>
POJ3728,The merchant(倍增LCA+分治)
查看>>
2019 ICPC Malaysia National,E. Optimal Slots(01背包变形)
查看>>
洛谷P1638 逛画展(双向队列)
查看>>
牛客练习赛51,D(二分图匹配)
查看>>
POJ2892,Tunnel Warfare(线段树维护连续区间)
查看>>
POJ3468,A Simple Problem with Integers(线段树-区间查询-区间更新)
查看>>
快速幂(递归)
查看>>
CodeForces 1101A Minimum Integer(思维)
查看>>
CodeForces 1102A Integer Sequence Dividing(思维)
查看>>
CodeForces 1087B Div Times Mod(思维)
查看>>
杭电ACM——4310,Hero(贪心)
查看>>
杭电ACM——1789,Doing Homework Again(贪心)
查看>>
北大ACM——2782,Bin Packing(贪心)
查看>>
北大ACM——4014,Dice(贪心)
查看>>
杭电ACM——4864,Task(贪心)
查看>>
北大ACM——3176,Cow Bowling(动态规划)
查看>>
北大ACM——2229,Sumsets(DP或思维)
查看>>
北大ACM——3186,Treats For The Cows(DP)
查看>>