@Order does not work on (CommandLine|Application)Runner @Bean methods #37905
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when the order of an
CommandLineRunner
orApplicationRunner
bean is defined on the bean method it is not taken into account.This is because
SpringApplication
sorts them by actual beans and does not consider the bean definitions.This behavior may be due to the fact that the ordering is determined collectively for both
CommandLineRunner
andApplicationRunner
.In other words, when a
CommandLineRunner
has order=1 and anApplicationRunner
has order=2, theCommandLineRunner
runs first, even though they are two different classes.The
BeanFactory
does not provide an API to retrieve ordered beans for two distinct types of beans. This is why it is currently limited to sorting them based solely on bean instances and not on their bean definitions.This PR introduces a sealed marker interface for
ApplicationRunner
andCommandLineRunner
.Then, using the interface to retrieve the beans in an ordered fashion, it takes into account the
@Order
on the bean definition(@Bean
method in this case).This allows for the use of
@Order
on@Bean
methods for bothCommandLineRunner
andApplicationRunner
.