关于Ordered接口,用过的人可能知道,这里我谈下自己的理解。也希望各位大神能给予指点。

源码如下:

/**
 * Interface that can be implemented by objects that should be
 * orderable, for example in a Collection.
 *
 * <p>The actual order can be interpreted as prioritization, with
 * the first object (with the lowest order value) having the highest
 * priority.
 *
 * <p>Note that there is a 'priority' marker for this interface:
 * {@link PriorityOrdered}. Order values expressed by PriorityOrdered
 * objects always apply before order values of 'plain' Ordered values.
 *
 * @author Juergen Hoeller
 * @since 07.04.2003
 * @see OrderComparator
 * @see org.springframework.core.annotation.Order
 */

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;

/**
* Return the order value of this object, with a
* higher value meaning greater in terms of sorting.
* <p>Normally starting with 0, with <code>Integer.MAX_VALUE</code>
* indicating the greatest value. Same order values will result
* in arbitrary positions for the affected objects.
* <p>Higher values can be interpreted as lower priority. As a
* consequence, the object with the lowest value has highest priority
* (somewhat analogous to Servlet "load-on-startup" values).
* @return the order value
*/
int getOrder();

}

当然这里并不是无故提出这个接口来看的。事由是由PropertyPlaceholderConfigurer这个类的加载顺序导致的。

这个类是实现了Ordered接口并且有这样一句话

private int order = Ordered.LOWEST_PRECEDENCE;  // default: same as non-Ordered

来说明PropertyPlaceholderConfigurer加载的顺序,如果你细心的话,Ordered上面的一个注释你会看到。

大概的翻译就是值越小加载优先级越高,而普通的对象我们定义的是没有实现Ordered接口的,即是他所说的

'plain' Ordered values.这样的对象的加载优先级比实现Ordered接口优先级最低的还要低。就是说虽然

PropertyPlaceholderConfigurer类的优先级是实现Ordered接口中最低的,但也比plain Object的优先级高。所以我们在

定义PropertyPlaceholderConfigurer的时候,可以把位置放后面而先用其值。如图:

最新文章

  1. 人脸识别引擎SeetaFace编译 ubuntu
  2. 11个并不广为人知,但值得了解的Python库
  3. 调用startActivityForResult,onActivityResult无响应的解决办法
  4. 升级webapi依赖的Newtonsoft.json的版本
  5. jQuery 一些小技巧
  6. SPRING IN ACTION 第4版笔记-第九章Securing web applications-008-使用非关系型数据库时如何验证用户(自定义UserService)
  7. xml_03
  8. 天兔(Lepus)监控系统快速安装部署
  9. .net 做工作流时,生成项目后工具箱里有关工作流的东西不显示解决方法
  10. Linux系统centos6.7上安装libevent
  11. 阅读:ECMAScript 6 入门(2)
  12. ML: 聚类算法-概论
  13. [Shell]Bash基本功能:通配符与特殊符号
  14. js 遍历行和列
  15. Qt Quick自定义样式一套
  16. 1. 通俗易懂解释知识图谱(Knowledge Graph)
  17. CSS非ASCII字符最佳实践
  18. 【BZOJ4003】[JLOI2015]城池攻占 可并堆
  19. 【Unity】开发WebGL内存概念具体解释和遇到的问题
  20. Java调用doNet webService方法

热门文章

  1. Asp.Net Core
  2. CSS高级技巧 图标字体ICONFONT的使用方法视频
  3. mojo 默认use utf8;
  4. MVC整个样例的源代码
  5. 04-UIKit(UINavigationController、NSAttributeString、UIImageView)
  6. 知识点1-3:MVC设计模式
  7. ModelAndView
  8. 使用ACE获取主机的IP地址
  9. 通过ip拨号器来了解广播接收者
  10. BZOJ 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛( dp )