首页 > 其他分享 >Spring OrderUtils工具的使用

Spring OrderUtils工具的使用

时间:2022-11-21 17:02:14浏览次数:52  
标签:return cached Spring result Integer 工具 null type OrderUtils

源码地址

源码阅读仓库: [SourceHot](https://github.com/SourceHot/spring-framework-read)

org.springframework.core.annotation.OrderUtils主要方法如下

getOrder 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;
    }
@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;
  }

标签:return,cached,Spring,result,Integer,工具,null,type,OrderUtils
From: https://blog.51cto.com/u_15485833/5874285

相关文章

  • HM-RocketMQ2.3【SpringBoot整合Dubbo】
    1前置条件安装依赖包下载dubbo-spring-boot-starter依赖包将dubbo-spring-boot-starter安装到本地仓库mvninstall-Dmaven.skip.test=true注意springboot整......
  • SpringBean生命周期
    SpringBean生命周期(~)简述:实例化(instantiateBean)——属性赋值(populateBean)——初始化(init)——销毁(destroy)详细:创建bean通过xml/注解@(Bean)。。等等方式注册bea......
  • ENVI新机器学习之异常探测分类工具操作手册
    异常探测是一种用于定位数据集中异常点的数据处理技术。异常值是指与数据集中的已知特征相比被认为不正常的值。例如,如果水是已知的特征,那么除水之外的任何东西都将被视为......
  • 20221121 Spring Boot 整合
    从Maven依赖关系分析spring-boot-starter-web|--spring-boot-starter-json|--|--jackson-databindSpringBoot配置属性参考org.springframework.boot.autoconfigu......
  • Spring Boot拦截器
    SpringMVC中提供了拦截器功能,可以根据URL对请求进行拦截,主要应用于登陆校验、权限验证、乱码解决、性能监控和异常处理等功能上。SpringBoot同样提供了拦截器功能。 ......
  • Spring Data (数据)MongoDB
    版本4.0.0SpringDataMongoDB项目将Spring的核心概念应用于使用MongoDB文档样式数据存储的解决方案的开发。我们提供了一个“模板”作为存储和查询文档的高级抽象。您可能......
  • 23 个让你的开发工作更轻松的工具
    英文|https://javascript.plainenglish.io/want-to-make-your-life-as-a-developer-a-lot-easier-use-these-tools-bf7796c2e12c翻译|杨小二创新工具几乎每天都会出现在......
  • 5个测试Vue.js程序的有用工具和库
    原文| https://blog.bitsrc.io/5-useful-tools-and-libraries-for-testing-vuejs-applications-13166f930da8作者|NethmiWijesinghe在过去的几年中,vue.js已成为最受欢......
  • SpringMVC知识
    1Spring框架Spring框架指的都是SpringFramework,它是很多模块的集合,使用这些模块可以很方便地协助我们进行开发。Spring自带IoC(InverseofControl:控制反转)和A......
  • spring boot调试redis报错:Unable to connect to Redis; 问题记录
    1、代码packagecom.example.spring1121;importorg.junit.jupiter.api.Test;importorg.springframework.beans.factory.annotation.Autowired;importorg.springfr......