spring-projects / spring-projects/spring-framework
Order metadata to enforce appearance at the end of a sorted collection
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
Overview
I kindly want to ask to resume the conversation on this topic.
It seems, that people have to deal with this problem.
What is desired, is that assume we have 3 beans: A, B and NoOp. And I assemble them into a List somewhere via:
@Autowired
private List<CommonInterface> list;
And what I want is the following:
for (var impl : list) {
if (impl.supports(o)) {
impl.doWork(o);
}
}
The NoOp implementation is required to be the last, since it is fallback. But I really do not care about the order of other beans in the List. What I want is to ensure, that the NoOp bean is the last one in the List.
The problem is that simply adding @Order with the lowest priority to the NoOp will not work.
I can, of course, define the @Order with higher priority for each bean except for NoOp, but this requires that every time a new implementation of CommonInterface being added, the developer must not forget about adding the corresponding order marker as well. Otherwise, the NoOp may not be the last, which can lead and probably would lead to bugs.
The deeper problem is that if I deal with already compiled code, and I cannot physically add any @Order/Ordered to the compiled implementations, but I need to add my own to the end of the list.
I hope we can collaboratively find a solution. Thank you.
Related Issues
- #24844
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the discussion linked from issue #31544 and the related issue #24844 to understand the existing ordering behavior and prior proposals. The issue does not name files, tests, or an entry point; an actionable implementation scope and acceptance criteria would need to be established before work can be considered done.
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