spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.49k stars 40.53k forks source link

Inconsistent behavior between `spring.factories` and `AutoConfiguration.imports` on Spring Boot 3.3.x #42016

Closed lucasoares closed 2 weeks ago

lucasoares commented 2 weeks ago

I'm upgrading Spring Boot from 2.7 and adapting the META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports changes related to the Auto Configuration system.

The behavior of the auto configuration system in integration tests using @SpringBootTest is inconsistent between using spring.factories and the new mode.

Before this change all the auto configurations were started when testing with @SpringBootTest. Now, with the org.springframework.boot.autoconfigure.AutoConfiguration.imports file, all the auto configuration classes stopped working in the integration tests. I have the spring-boot-autoconfigure-processor dependency and I can see all my auto configuration classes in the generated spring-autoconfigure-metadata.properties so I'm assuming the imports file is correct, but when running the test no auto configuration classes are called.

The thing that made me realize that there is an inconsistent between the both uses is because if I use the spring.factories as before but keep the Spring Boot 3.3 version, the auto configuration classes are loaded normally in the integration tests.

The only way I find to make it work using the imports file is by adding the @EnableAutoConfiguration annotation in my test class, but I have a lot of projects and tests and since I can't find this documented in any releasing notes, I'm assuming this is a bug.

ps.: Im using @SpringBootTest with the classes attribute to specify few classes in this specific test.

bclozel commented 2 weeks ago

Please share a minimal sample that fails with 3.3 and works with 2.7

lucasoares commented 2 weeks ago

Please share a minimal sample that fails with 3.3 and works with 2.7

I just notice that my application was using bootstrap configuration and not auto configuration. My bad haha

Thanks.

bclozel commented 2 weeks ago

Thanks for letting us know