V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Newyorkcity
V2EX  ›  问与答

请教 SpringBoot 中 PriorityOrdered 这个接口,它的注释的后半段不太理解意思

  •  
  •   Newyorkcity · 2020 年 10 月 22 日 · 1102 次点击
    这是一个创建于 1994 天前的主题,其中的信息可能已经有所发展或是发生改变。

    org.springframework.core.PriorityOrdered

    Extension of the Ordered interface, expressing a priority ordering: PriorityOrdered objects are always applied before plain Ordered objects regardless of their order values.

    When sorting a set of Ordered objects, PriorityOrdered objects and plain Ordered objects are effectively treated as two separate subsets, with the set of PriorityOrdered objects preceding the set of plain Ordered objects and with relative ordering applied within those subsets.

    这两段还是好懂的。就是实现了 PriorityOrdered 接口的 objects 一定在只是实现了 Ordered 接口的 objects 前。在其内部再按照 getOrder() 的值来排序。

    后两段就不是很明白,想请教各位:

    This is primarily a special-purpose interface, used within the framework itself for objects where it is particularly important to recognize prioritized objects first, potentially without even obtaining the remaining objects. A typical example: prioritized post-processors in a Spring ApplicationContext.

    Note: PriorityOrdered post-processor beans are initialized in a special phase, ahead of other post-processor beans. This subtly affects their autowiring behavior: they will only be autowired against beans which do not require eager initialization for type matching.

    感觉上像是在说这个接口用于 Spring 框架内部,如果你不是 Spring 框架开发者最好别用这个接口?

    然后 Spring 框架内部对这个接口最经典的应用就是在 post-processors 上。BeanPostProcessor ?

    主要就是 recognize prioritized objects firstthey will only be autowired against beans which do not require eager initialization for type matching. 这两句话对应的具体行为想不到,麻烦大佬举个例子?

    谢谢

    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5231 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 03:53 · PVG 11:53 · LAX 20:53 · JFK 23:53
    ♥ Do have faith in what you're doing.