Skip to content

Commit 87c39de

Browse files
committed
Introduce RuntimeHints support in AotContextLoader
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
1 parent 7e9ac12 commit 87c39de

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

spring-test/src/main/java/org/springframework/test/context/aot/AotContextLoader.java

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.test.context.aot;
1818

19+
import org.springframework.aot.hint.RuntimeHints;
1920
import org.springframework.context.ApplicationContext;
2021
import org.springframework.context.ApplicationContextInitializer;
2122
import org.springframework.context.ConfigurableApplicationContext;
@@ -25,9 +26,9 @@
2526

2627
/**
2728
* Strategy interface for loading an {@link ApplicationContext} for build-time
28-
* {@linkplain #loadContextForAotProcessing AOT processing} as well as run-time
29-
* {@linkplain #loadContextForAotRuntime AOT execution} for an integration test
30-
* managed by the Spring TestContext Framework.
29+
* {@linkplain #loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)
30+
* AOT processing} as well as run-time {@linkplain #loadContextForAotRuntime
31+
* AOT execution} for an integration test managed by the Spring TestContext Framework.
3132
*
3233
* <p>{@code AotContextLoader} is an extension of the {@link SmartContextLoader}
3334
* SPI that allows a context loader to optionally provide ahead-of-time (AOT)
@@ -69,10 +70,38 @@ public interface AotContextLoader extends SmartContextLoader {
6970
* application context
7071
* @return a new {@code GenericApplicationContext}
7172
* @throws ContextLoadException if context loading failed
73+
* @see #loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)
7274
* @see #loadContextForAotRuntime(MergedContextConfiguration, ApplicationContextInitializer)
7375
*/
7476
ApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig) throws Exception;
7577

78+
/**
79+
* Load a new {@link ApplicationContext} for AOT build-time processing based
80+
* on the supplied {@link MergedContextConfiguration}, configure the context,
81+
* and return the context.
82+
* <p>This variant of {@code loadContextForAotProcessing(...)} accepts a
83+
* {@link RuntimeHints} argument. See the documentation for
84+
* {@link #loadContextForAotProcessing(MergedContextConfiguration)} for details
85+
* regarding the contract of this method.
86+
* <p>The default implementation of this method delegates to
87+
* {@code loadContextForAotProcessing(MergedContextConfiguration)}. Note,
88+
* however, that the framework only invokes this method as of Spring Framework
89+
* 6.2.4.
90+
* @param mergedConfig the merged context configuration to use to load the
91+
* application context
92+
* @param runtimeHints the runtime hints
93+
* @return a new {@code GenericApplicationContext}
94+
* @throws ContextLoadException if context loading failed
95+
* @see #loadContextForAotProcessing(MergedContextConfiguration)
96+
* @see #loadContextForAotRuntime(MergedContextConfiguration, ApplicationContextInitializer)
97+
* @since 6.2.4
98+
*/
99+
default ApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig,
100+
RuntimeHints runtimeHints) throws Exception {
101+
102+
return loadContextForAotProcessing(mergedConfig);
103+
}
104+
76105
/**
77106
* Load a new {@link ApplicationContext} for AOT run-time execution based on
78107
* the supplied {@link MergedContextConfiguration} and

spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ ClassName processAheadOfTime(MergedContextConfiguration mergedConfig,
331331
* create {@link GenericApplicationContext GenericApplicationContexts}.
332332
* @throws TestContextAotException if an error occurs while loading the application
333333
* context or if one of the prerequisites is not met
334-
* @see AotContextLoader#loadContextForAotProcessing(MergedContextConfiguration)
334+
* @see AotContextLoader#loadContextForAotProcessing(MergedContextConfiguration, RuntimeHints)
335335
*/
336336
private GenericApplicationContext loadContextForAotProcessing(
337337
MergedContextConfiguration mergedConfig) throws TestContextAotException {
@@ -345,7 +345,7 @@ private GenericApplicationContext loadContextForAotProcessing(
345345

346346
if (contextLoader instanceof AotContextLoader aotContextLoader) {
347347
try {
348-
ApplicationContext context = aotContextLoader.loadContextForAotProcessing(mergedConfig);
348+
ApplicationContext context = aotContextLoader.loadContextForAotProcessing(mergedConfig, this.runtimeHints);
349349
if (context instanceof GenericApplicationContext gac) {
350350
return gac;
351351
}

0 commit comments

Comments
 (0)