-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Description
While testing for #12318, @snicoll found a limitation in the current ordering between @ImportAutoConfiguration and @EnableAutoConfiguration.
Consider the following test application:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {
WebTestClientSpringBootTestIntegrationTests.TestConfiguration.class,
ExampleWebFluxApplication.class })
@AutoConfigureWebTestClient
public class WebTestClientSpringBootTestIntegrationTests {
}This test starts a Spring Boot application with all auto-configurations and use the @AutoConfigureWebTestClient test annotation. The current issue is that all auto-configurations imported by @AutoConfigureWebTestClient cannot rely on @AutoConfigureAfter/@AutoConfigureBefore, since things are processed in two different phases.
Currently:
@EnableAutoConfigurationis usingAutoConfigurationImportSelector, which is ordered atOrdered.LOWEST_PRECEDENCE - 1@ImportAutoConfigurationis usingImportAutoConfigurationImportSelector(itself extending fromAutoConfigurationImportSelector), which is ordered atsuper.getOrder() - 1, soOrdered.LOWEST_PRECEDENCE - 2.
Because of this, ImportAutoConfigurationImportSelector auto-configurations are processed before Spring Boot auto-configurations.
Solutions
Setting ImportAutoConfigurationImportSelector::getOrder to Ordered.LOWEST_PRECEDENCE fixes the issue, and the whole Spring Boot build is green.
Doing that change would imply that:
- Ordering and bean conditions (like
@AutoConfigureBefore/@AutoConfigureAfter) can only be applied to a set of auto-configurations imported by the same selector. So for@ImportAutoConfiguration, those are only applied within the scope of test slicing annotations. - In the case of
@SpringBootTest, we agree that@ImportAutoConfigurationshould always run after the Spring Boot auto-configurations and that ordering and bean conditions on test auto-configurations won't apply to auto-configurations contributed by@EnableAutoConfiguration
Flagging this as for:team-attention.