Spring OrderUtils详解

简介: 《读尽源码》
  • org.springframework.core.annotation.OrderUtils主要方法如下
  1. getOrder
  2. getPriority
  • 测试类org.springframework.core.annotation.OrderUtilsTests
@Nullable
    public static Integer getOrder(Class<?> type) {
        // 缓存中获取
        Object cached = orderCache.get(type);
        if (cached != null) {
            // 返回 int
            return (cached instanceof Integer ? (Integer) cached : null);
        }
        /**
         * 注解工具类,寻找{@link Order}注解
         */
        Order order = AnnotationUtils.findAnnotation(type, Order.class);
        Integer result;
        if (order != null) {
            // 返回
            result = order.value();
        } else {
            result = getPriority(type);
        }
        // key: 类名,value: intValue
        orderCache.put(type, (result != null ? result : NOT_ANNOTATED));
        return result;
    }
Copy to clipboardErrorCopied
@Nullable
    public static Integer getPriority(Class<?> type) {
        if (priorityAnnotationType == null) {
            return null;
        }
        // 缓存中获取
        Object cached = priorityCache.get(type);
        if (cached != null) {
            // 不为空返回
            return (cached instanceof Integer ? (Integer) cached : null);
        }
        // 注解工具获取注解
        Annotation priority = AnnotationUtils.findAnnotation(type, priorityAnnotationType);
        Integer result = null;
        if (priority != null) {
            // 获取 value
            result = (Integer) AnnotationUtils.getValue(priority);
        }
        // 向缓存插入数据
        priorityCache.put(type, (result != null ? result : NOT_ANNOTATED));
        return result;
    }
相关文章
|
4月前
|
XML Java 开发者
【Spring】Spring是什么?
【Spring】Spring是什么?
【Spring】Spring是什么?
|
5月前
|
前端开发 Java 开发者
【Spring】 ——初识Spring
【Spring】 ——初识Spring
39 0
|
9月前
|
存储 XML Java
|
10月前
|
Java Spring
Spring 是什么?
Spring 是什么?
43 0
|
10月前
|
XML Java 数据库连接
Spring 代码优化技巧(大全1)(一)
Spring 代码优化技巧(大全1)
86 0
|
Java 索引 Spring
|
XML 前端开发 Oracle
spring知识总结(一)
spring知识总结(一)
204 0
spring知识总结(一)
|
存储 Java 程序员
深入理解 Spring finishBeanFactoryInitialization (一)
深入理解 Spring finishBeanFactoryInitialization (一)
133 0
|
缓存 安全 Java
Spring详解【下】
1、Spring 1.1、简介 Spring:春天 >给软件行业带来了春天! 2002,首次推出了Spring框架的雏形:interface21框架! Spring框架即以interface21框架为基础,经过重新的设计,并不断的丰富其内涵,于2004年3月24日,发布了1.0正式版。 Rod Jo