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

2021-12-01  本文已影响0人  归去来ming
// 值越低,优先级越高
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;
上一篇 下一篇

猜你喜欢

热点阅读