Description
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
AnnotatedClassFinder
during AOT build-time processing. - Store the class name of the
@SpringBootConfiguration
class for later retrieval. - Retrieve the
@SpringBootConfiguration
class 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
String
and the value is anString
- initial support should provide convenience methods for retrieving an attribute as a
String
orboolean
- if deemed necessary, generic support can later be added for providing a
CodeBlock
or statement to create the object in the attributes store
- if deemed necessary, generic support can later be added for providing a
- 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