美文网首页
2021-12-01 Spring源码中的Ordered和Pri

2021-12-01 Spring源码中的Ordered和Pri

作者: 归去来ming | 来源:发表于2021-12-01 10:30 被阅读0次
    // 值越低,优先级越高
    public interface Ordered {
    
        /**
         * Useful constant for the highest precedence value.
         * @see java.lang.Integer#MIN_VALUE
         */
        int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;
    
        /**
         * Useful constant for the lowest precedence value.
         * @see java.lang.Integer#MAX_VALUE
         */
        int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
    
    
        /**
         * Get the order value of this object.
         * <p>Higher values are interpreted as lower priority. As a consequence,
         * the object with the lowest value has the highest priority (somewhat
         * analogous to Servlet {@code load-on-startup} values).
         * <p>Same order values will result in arbitrary sort positions for the
         * affected objects.
         * @return the order value
         * @see #HIGHEST_PRECEDENCE
         * @see #LOWEST_PRECEDENCE
         */
        int getOrder();
    
    }
    
    public interface PriorityOrdered extends Ordered {
    
    }
    

    看一下实现了PriorityOrdered的类有哪些?然后重点看一下 AutowiredAnnotationBeanPostProcessor类和RequiredAnnotationBeanPostProcessor


    image.png
    // AutowiredAnnotationBeanPostProcessor
    private int order = Ordered.LOWEST_PRECEDENCE - 2;
    
    // RequiredAnnotationBeanPostProcessor
    private int order = Ordered.LOWEST_PRECEDENCE - 1;
    

    相关文章

      网友评论

          本文标题:2021-12-01 Spring源码中的Ordered和Pri

          本文链接:https://www.haomeiwen.com/subject/dphsxrtx.html