Skip to content

Add support for relative ordering #24844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
snicoll opened this issue Apr 2, 2020 · 5 comments
Open

Add support for relative ordering #24844

snicoll opened this issue Apr 2, 2020 · 5 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement

Comments

@snicoll
Copy link
Member

snicoll commented Apr 2, 2020

Overview

Our current support for @Order/Ordered uses an absolute number with a default value of "lowest precedence" (i.e. Integer.MAX_VALUE). We also have PriorityOrdered to override such ordering in certain scenarios.

One problem with the current default value is that it is not natural for customizers where you'd want the "default" ones to be at a given order with the ability of custom instance to run before, or after. Such a default must provide a value as there is no way to run "after" with the current default value. A natural value for that is zero with negative values being processed before and positive values being processed after.

A better way to express ordering is to express it relative to another concept. You may need to run/customize/execute before or after another "instance". In Spring Boot, we've essentially implemented that with @AutoConfigureBefore and @AutoConfigureAfter to order auto-configurations.

This issue is to discuss if there is an appetite to provide such constructs in the core framework, with an SPI that would let us order things (potentially being honored in ObjectProvider#orderedStream().

Related Issues

@andersonkyle
Copy link

This would be particularly nice for servlet filter registration.

@sbrannen sbrannen added for: team-attention in: core Issues in core modules (aop, beans, core, context, expression) labels Apr 27, 2020
@mjustin
Copy link

mjustin commented Mar 3, 2021

As a user, I can confirm this would be useful. The current approach I have to follow is open the bean, see if there's an order defined, and then order relative to that (hoping that it's not at the max/min in a way that would prevent going before/after it). When there isn't an order defined, I need to pull open @Order.value() to see what the default is (LOWEST_PRECEDENCE) and make sure I order relative to that.

Then I write something like the following, where the reasoning is in the comments, rather than being declarative in the code itself:

@Order(Ordered.LOWEST_PRECEDENCE - 1) // Higher precedence than SomeOtherThing

@rstoyanchev rstoyanchev added this to the 6.0.x milestone Aug 2, 2022
@bclozel bclozel added type: enhancement A general enhancement status: pending-design-work Needs design work before any code can be developed and removed for: team-attention status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 2, 2022
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Aug 2, 2022

Team Decision: this is worth doing to provide sufficient control over ordering. There are some design decisions to be thought through such as relative vs explicit ordering, how to refer to others for relative ordering, etc.

@spencergibb
Copy link
Member

We do this in spring cloud gateway with constants, so this would be useful

@sbrannen
Copy link
Member

sbrannen commented Apr 8, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

8 participants