Overview
For certain use cases it would be beneficial to be able to compute something during AOT build-time processing and then retrieve the result of that computation during AOT run-time execution.
Use Case
The SpringBootTestContextBootstrapper performs class path scanning for the @SpringBootConfiguration class using a utility called AnnotatedClassFinder; however, class path scanning does not work within a GraalVM native image.
In the Spring Native project, the AnnotatedClassFinder worked without modification because Spring's component indexer was used to index annotated components during the build; however, in Spring Framework 6.0 and Spring Boot 3.0 we do not want to rely on the component indexer.
Ideally, SpringBootTestContextBootstrapper should be able to:
- Use the
AnnotatedClassFinderduring AOT build-time processing. - Store the class name of the
@SpringBootConfigurationclass for later retrieval. - Retrieve the
@SpringBootConfigurationclass name that was discovered at build time during AOT run-time execution.
Proposal
Introduce an AotTestAttributes mechanism in the Spring TestContext Framework.
- conceptually similar to
org.springframework.core.AttributeAccessor - must allow an AOT-aware component to contribute a key-value pair, where the key is a
Stringand the value is anString - initial support should provide convenience methods for retrieving an attribute as a
Stringorboolean - if deemed necessary, generic support can later be added for providing a
CodeBlockor statement to create the object in the attributes store - must generate the necessary source code during the AOT processing phase in the testing framework to create a persistent map of the attributes
- must provide a mechanism for accessing the stored attributes during AOT run-time execution
Comment From: sbrannen
I've pushed a working prototype for TestAotProperties here:
https://github.com/spring-projects/spring-framework/compare/main...sbrannen:TestAotProperties
@philwebb, let's see if this meets the needs of SpringBootTestContextBootstrapper.