spring-projects / spring-projects/spring-framework

Add support for relative ordering

Open
#24,844 9 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

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

  • #34670

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the issue's references to @Order, Ordered, PriorityOrdered, and ObjectProvider#orderedStream(), then compare them with Spring Boot's @AutoConfigureBefore and @AutoConfigureAfter approach. Done would require an agreed core-framework SPI and defined relative-ordering behavior; the issue currently asks whether such a design should exist.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.