You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When executing a test with Spring, it caches context based on a MergedContextConfiguration. When using an @AutoConfigure annotation, each test package generates a new application context instead of reusing an existing one that is supposed to match.
After digging problem, I find that ImportsContextCustomizer adds AutoConfigurationPackages$PackageImport while finding a @Import(AutoConfigurationPackages.Registrar.class) into annotation "hierarchy":
From my example:
While @AutoConfigurationPackage is supposed to add annotated element package as a source. But in this case, it is unexpected but also cache key doesn't take into account real impact on configuration. If there no additional element, application context is supposed to be the same.
The text was updated successfully, but these errors were encountered:
The cache key issue is quite subtle here. The @AutoConfigurationPackage is used to register a package that will be picked up things like JPA registration. This means that it could change the contents of the ApplicationContext so a different cache key is required.
I'm not convinced that @ImportAutoConfiguration should really be annotated with @AutoConfigurationPackage. It really services a different purpose and I don't think it totally makes sense.
The problem is that removing the annotation is potentially a breaking change and something that I don't think we should do in 1.5.x. It's unfortunate that extra contexts are created, but I think we might need to live with that until 2.0 is released.
Uh oh!
There was an error while loading. Please reload this page.
Spring Boot version: 1.5.4
When executing a test with Spring, it caches context based on a
MergedContextConfiguration
. When using an@AutoConfigure
annotation, each test package generates a new application context instead of reusing an existing one that is supposed to match.See https://github.com/loganmzz/spring-boot-context-cache-and-autoconfigure as an example.
After digging problem, I find that
ImportsContextCustomizer
addsAutoConfigurationPackages$PackageImport
while finding a@Import(AutoConfigurationPackages.Registrar.class)
into annotation "hierarchy":From my example:
DemoApplicationTests
@AutoConfigureJson
@ImportAutoConfiguration
@AutoConfigurationPackage
@Import(AutoConfigurationPackages.Registrar.class)
While
@AutoConfigurationPackage
is supposed to add annotated element package as a source. But in this case, it is unexpected but also cache key doesn't take into account real impact on configuration. If there no additional element, application context is supposed to be the same.The text was updated successfully, but these errors were encountered: