V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Newyorkcity
V2EX  ›  问与答

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

  •  
  •   Newyorkcity · Oct 22, 2020 · 1172 views
    This topic created in 2019 days ago, the information mentioned may be changed or developed.

    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. 这两句话对应的具体行为想不到,麻烦大佬举个例子?

    谢谢

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2461 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:34 · PVG 15:34 · LAX 00:34 · JFK 03:34
    ♥ Do have faith in what you're doing.