-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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.