Skip to content

Spring context cache when using @AutoConfigure* annotations "breaks" on each test package #9694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
loganmzz opened this issue Jul 6, 2017 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@loganmzz
Copy link

loganmzz commented Jul 6, 2017

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 adds AutoConfigurationPackages$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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 6, 2017
@philwebb
Copy link
Member

philwebb commented Jul 6, 2017

Thanks for the same and for the analysis.

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.

@philwebb philwebb added priority: normal type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 6, 2017
@philwebb philwebb added this to the 2.0.0.M3 milestone Jul 6, 2017
@wilkinsona
Copy link
Member

Isn't this a duplicate of #9282?

@wilkinsona wilkinsona marked this as a duplicate of #9282 Jul 21, 2017
@philwebb philwebb removed this from the 2.0.0.M3 milestone Jul 24, 2017
@philwebb
Copy link
Member

Indeed, it's a duplicate of #9282

@philwebb philwebb added status: duplicate A duplicate of another issue and removed priority: normal type: bug A general bug labels Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants