Register runtime hints for ApplicationContextInitializers in the TCF
This commit introduces automatic registration of runtime hints for ApplicationContextInitializers configured via the `initializers` attribute in @ContextConfiguration. See gh-29021
This commit is contained in:
@@ -112,6 +112,7 @@ public class TestContextAotGenerator {
|
||||
mergedConfigMappings.forEach((mergedConfig, testClasses) -> {
|
||||
logger.debug(LogMessage.format("Generating AOT artifacts for test classes %s",
|
||||
testClasses.stream().map(Class::getName).toList()));
|
||||
registerHintsForMergedConfig(mergedConfig);
|
||||
try {
|
||||
// Use first test class discovered for a given unique MergedContextConfiguration.
|
||||
Class<?> testClass = testClasses.get(0);
|
||||
@@ -174,8 +175,6 @@ public class TestContextAotGenerator {
|
||||
Consider annotating test class [%s] with @ContextConfiguration or \
|
||||
@ContextHierarchy.""".formatted(testClass.getName()));
|
||||
|
||||
registerDeclaredConstructors(contextLoader.getClass());
|
||||
|
||||
if (contextLoader instanceof AotContextLoader aotContextLoader) {
|
||||
try {
|
||||
ApplicationContext context = aotContextLoader.loadContextForAotProcessing(mergedConfig);
|
||||
@@ -227,6 +226,14 @@ public class TestContextAotGenerator {
|
||||
.registerType(TypeReference.of(className), MemberCategory.INVOKE_PUBLIC_METHODS);
|
||||
}
|
||||
|
||||
private void registerHintsForMergedConfig(MergedContextConfiguration mergedConfig) {
|
||||
ContextLoader contextLoader = mergedConfig.getContextLoader();
|
||||
if (contextLoader != null) {
|
||||
registerDeclaredConstructors(contextLoader.getClass());
|
||||
}
|
||||
mergedConfig.getContextInitializerClasses().forEach(this::registerDeclaredConstructors);
|
||||
}
|
||||
|
||||
private void registerDeclaredConstructors(Class<?> type) {
|
||||
ReflectionHints reflectionHints = this.runtimeHints.reflection();
|
||||
reflectionHints.registerType(type, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
|
||||
Reference in New Issue
Block a user