Skip to content
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

AotContextLoader has no way to register custom hints #34513

Open
snicoll opened this issue Feb 28, 2025 · 0 comments
Open

AotContextLoader has no way to register custom hints #34513

snicoll opened this issue Feb 28, 2025 · 0 comments
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Feb 28, 2025

I am looking at spring-projects/spring-boot#44461 and what my options are to register a reflection hints for the main method that SpringBootContextLoader invokes via reflection.

It is an AotContextLoader but I don't have a way to get the RuntimeHints to register the necessary hint. Looking at the current arrangement, I don't see something that we could implement that gives us the MergedContextConfiguration and RuntimeHints. The closest I found is MergedContextConfigurationRuntimeHints but it's private.

Have I missed something? https://github.com/spring-projects/spring-boot/blob/93648792b14301264c7fdbb4ea343b9092a0d7ed/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java#L128 is where I'd need some way to get the runtime hints.

@snicoll snicoll added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 28, 2025
snicoll added a commit to spring-projects/spring-boot that referenced this issue Feb 28, 2025
This commit makes sure to register the necessary hints to invoke the
main method of any bean available in the context. This is necessary
for tests that use the UseMainMethod feature.

This generates more hints than strictly necessary as there isn't a
way to contribute hints based on a ContextLoader, see
spring-projects/spring-framework#34513 for
more details.

Closes gh-44461
@jhoeller jhoeller added the in: test Issues in the test module label Feb 28, 2025
@sbrannen sbrannen self-assigned this Feb 28, 2025
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 28, 2025
@sbrannen sbrannen added this to the 6.2.4 milestone Feb 28, 2025
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Feb 28, 2025
This commit introduces a new loadContextForAotProcessing(...) variant
in AotContextLoader which accepts a RuntimeHints argument. This new
method is an interface default method which delegates to the existing
loadContextForAotProcessing(MergedContextConfiguration) variant.

Note, however, that the framework now only invokes the new
loadContextForAotProcessing(...) variant within TestContextAotGenerator.

Closes spring-projectsgh-34513
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Feb 28, 2025
This commit introduces a new loadContextForAotProcessing(...) variant
in AotContextLoader which accepts a RuntimeHints argument. This new
method is an interface default method which delegates to the existing
loadContextForAotProcessing(MergedContextConfiguration) variant for
backward compatibility.

In addition, the original loadContextForAotProcessing(...) variant is
now deprecated and has been converted to an interface default method
which throws an UnsupportedOperationException.

Note, however, that the framework now only invokes the new
loadContextForAotProcessing(...) variant within TestContextAotGenerator.

Closes spring-projectsgh-34513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants