Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Filter ContextCustomizerFactory implementations that are only necessary at build time #1242

Closed
snicoll opened this issue Nov 9, 2021 · 6 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@snicoll
Copy link
Contributor

snicoll commented Nov 9, 2021

Overview

Consider the following use case:

@SpringBootTest
@Import(SomeConfiguration.class)
class MyTest { ... }

At build time, the processing of @SpringBootTest registers the necessary infrastructure to parse SomeConfiguration. At runtime, this process runs again (because it is part of SpringBootTestContextBootstrapper, via ImportsContextCustomizer).

Parsing configuration classes in a native image should not happen as it was done already at build time.

Deliverables

This task is to validate that the right AOT infrastructure is generated with such a test and to prevent it from happening again at runtime.

There might be other ContextCustomizer implementations that are running twice and should be handled the same way.

@snicoll snicoll added the type: task A general task label Nov 9, 2021
@snicoll snicoll added this to the 0.11.0 milestone Nov 9, 2021
@sdeleuze sdeleuze modified the milestones: 0.11.0, 0.11.0-RC1 Nov 11, 2021
@sdeleuze
Copy link
Contributor

This is breaking petclinic-jdbc tests (at least) so let's try to solve it for RC1.

@sbrannen sbrannen added theme: aot type: bug A general bug and removed type: task A general task labels Nov 12, 2021
@snicoll snicoll self-assigned this Nov 15, 2021
@snicoll
Copy link
Contributor Author

snicoll commented Nov 15, 2021

@sbrannen can you please give us a status update of what you've tried so that I don't duplicate the effort?

@snicoll
Copy link
Contributor Author

snicoll commented Nov 15, 2021

Everything goes in the direction of being able to swap the TestContextBootstrapper that the test uses. We won't be able to get that short term so rewriting spring.factories to remove org.springframework.boot.test.context.ImportsContextCustomizerFactory could be one good option.

@snicoll snicoll changed the title Investigate how to support use of ContextCustomizer Filter ContextCustomizerFactory implementations that are only necessary at build time Nov 15, 2021
@sbrannen
Copy link
Contributor

Everything goes in the direction of being able to swap the TestContextBootstrapper that the test uses.

Indeed, that may be the most robust solution in the end.

We won't be able to get that short term so rewriting spring.factories to remove org.springframework.boot.test.context.ImportsContextCustomizerFactory could be one good option.

I thought about that as well, but the thing is that the context customizers have to be present/instantiated/registered in order for the MergedContextConfiguration to do its job as the key for the ContextCache.

@sbrannen
Copy link
Contributor

@sbrannen can you please give us a status update of what you've tried so that I don't duplicate the effort?

I didn't have a solution in place. Rather, I was investigating/contemplating possible solutions.

One thing I was considering was "caching" the calculated ContextCustomizerKey (or what it needs as input) for the ImportsContextCustomizer at build time, making that available via some generated factory (or similar approach), and then implementing a native substitution for the ImportsContextCustomizer constructor that (re)builds the ContextCustomizerKey from input retrieved from the generated factory -- effectively bypassing the ContextCustomizerKey#determineImports(Set<Annotation>, Class<?>) logic within the native image.

@snicoll
Copy link
Contributor Author

snicoll commented Nov 15, 2021

Let's follow-up on #1262 for the cache key problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

3 participants