- Author: HuiFer
- 源码阅读仓库: SourceHot-Spring
org.springframework.core.annotation.OrderUtils
主要方法如下 - getOrder
- getPriority
- 测试类
org.springframework.core.annotation.OrderUtilsTests
@NullablepublicstaticIntegergetOrder(Class<?> type) { // 缓存中获取Objectcached = orderCache.get(type); if (cached != null) { // 返回 intreturn (cachedinstanceofInteger ? (Integer) cached : null); } /** * 注解工具类,寻找{@link Order}注解 */Orderorder = AnnotationUtils.findAnnotation(type, Order.class); Integerresult; if (order != null) { // 返回result = order.value(); } else { result = getPriority(type); } // key: 类名,value: intValueorderCache.put(type, (result != null ? result : NOT_ANNOTATED)); returnresult; }
@NullablepublicstaticIntegergetPriority(Class<?> type) { if (priorityAnnotationType == null) { returnnull; } // 缓存中获取Objectcached = priorityCache.get(type); if (cached != null) { // 不为空返回return (cachedinstanceofInteger ? (Integer) cached : null); } // 注解工具获取注解Annotationpriority = AnnotationUtils.findAnnotation(type, priorityAnnotationType); Integerresult = null; if (priority != null) { // 获取 valueresult = (Integer) AnnotationUtils.getValue(priority); } // 向缓存插入数据priorityCache.put(type, (result != null ? result : NOT_ANNOTATED)); returnresult; }