-
Couldn't load subscription status.
- Fork 41.6k
Description
I have two AutoConfiguration classes, with an ordering dependency defined via @AutoConfigureBefore but no direct dependency between them (setting up some legacy libraries that have not great static initialization and implicit static dependencies between themselves).
I have also added @AutoConfigurationOrder trying to resolve that and observed the same behaviors. I left that out in my sample.
In the absence of any dependency, the two autoconfigurations run in the order defined by the @AutoConfigureBefore and the components are successfully instantiated.
However, if any component in the app adds a dependency on a component from the second autoconfiguration, that component is created and injected before any components in the first autoconfiguration are created.
This repo demonstrates the failure case:
https://github.com/cfieber/autoconfig-order
see https://github.com/cfieber/autoconfig-order/blob/master/bootapp/src/test/java/bootapp/BreakyTest.java specifically
Observed on both spring-boot 2.2.6.RELEASE and 2.3.1.RELEASE
I believe I can work around this problem by making the initializing component in the first autoconfiguration a bean post processor or something to cause it to initialize early, however that feels a bit heavy handed and less obvious than expressing the dependency with the autoconfiguration orderings.
The two autoconfigurations do not have direct dependencies (or even @DependsOn references) because there are a few different ways to configure the first dependency so I don't want a direct reference there.