Currently, when the order of an CommandLineRunner or ApplicationRunner bean is defined on the bean method it is not taken into account.
@Bean
@Order(10)
CommandLineRunner runner() {
return (args) -> ...;
}
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 and ApplicationRunner.
In other words, when a CommandLineRunner has order=1 and an ApplicationRunner has order=2, the CommandLineRunner 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 and CommandLineRunner.
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 both CommandLineRunner and ApplicationRunner.