
常用注解使用总结系列: @Order 注解
发布日期:2021-05-09 04:56:28
浏览次数:15
分类:博客文章
本文共 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),所以先打印出来
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2025年03月31日 13时43分18秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
6 个 Linux 运维典型问题
2019-03-05
取消vim打开文件全是黄色方法
2019-03-05
一个系统部署多个tomcat实例
2019-03-05
QT :warning LNK4042: 对象被多次指定;已忽略多余的指定
2019-03-05
Typescript 学习笔记六:接口
2019-03-05
MySQL-时区导致的时间前后端不一致
2019-03-05
sctf_2019_easy_heap
2019-03-06
bcolz的新操作
2019-03-06
delete对象时会自动调用类的析构函数
2019-03-06
POD类型
2019-03-06
Head First设计模式——迭代器模式
2019-03-06
记一次讲故事机器人的开发-我有故事,让机器人来读
2019-03-06
netcore中使用session
2019-03-06
远程触发Jenkins的Pipeline任务的并发问题处理
2019-03-06
【wp】HWS计划2021硬件安全冬令营线上选拔赛
2019-03-06
Ef+T4模板实现代码快速生成器
2019-03-06
Java面试题:Servlet是线程安全的吗?
2019-03-06
Linux探测工具BCC(可观测性)
2019-03-06
采坑 - 字符串的 "" 与 pd.isnull()
2019-03-06