https://github.com/spring-projects/spring-boot/blob/2642b040732de02e0e4ae88d2f16df902bc6226f/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java#L103
remove Initially sort alphabetically https://github.com/spring-projects/spring-boot/blob/2642b040732de02e0e4ae88d2f16df902bc6226f/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java#L60
It is suggested to change it to LinkedHashMap
, so that org.springframework.boot.autoconfigure.EnableAutoConfiguration
in spring.factories
can be sorted according to the order of addition
reason:
1. Sorting by alphabet is not controllable, because the class name may change during the development process
2. In the same file spring.factories
, it can be controlled according to the order in which the configuration class
is added
Comment From: wilkinsona
Thanks for the suggestion, but ordering auto-configuration files based on a single spring.factories
file won't work.
Auto-configuration can be declared across any number of spring.factories
files and they need to be ordered based on the complete set, not on a per-spring.factories-file basis. As described in the documentation, auto-configuration should be ordered relatively using @AutoConfigureBefore
or @AutoConfigureAfter
or absolutely using @AutoConfigureOrder
.
The sorting by class name is used as a fallback to provide stable ordering across all known auto-configurations for those that have not configured their ordering.