@ -112,6 +112,7 @@ public class TestContextAotGenerator {
mergedConfigMappings . forEach ( ( mergedConfig , testClasses ) - > {
mergedConfigMappings . forEach ( ( mergedConfig , testClasses ) - > {
logger . debug ( LogMessage . format ( "Generating AOT artifacts for test classes %s" ,
logger . debug ( LogMessage . format ( "Generating AOT artifacts for test classes %s" ,
testClasses . stream ( ) . map ( Class : : getName ) . toList ( ) ) ) ;
testClasses . stream ( ) . map ( Class : : getName ) . toList ( ) ) ) ;
registerHintsForMergedConfig ( mergedConfig ) ;
try {
try {
// Use first test class discovered for a given unique MergedContextConfiguration.
// Use first test class discovered for a given unique MergedContextConfiguration.
Class < ? > testClass = testClasses . get ( 0 ) ;
Class < ? > testClass = testClasses . get ( 0 ) ;
@ -174,8 +175,6 @@ public class TestContextAotGenerator {
Consider annotating test class [ % s ] with @ContextConfiguration or \
Consider annotating test class [ % s ] with @ContextConfiguration or \
@ContextHierarchy. "" " . formatted ( testClass . getName ( ) ) ) ;
@ContextHierarchy. "" " . formatted ( testClass . getName ( ) ) ) ;
registerDeclaredConstructors ( contextLoader . getClass ( ) ) ;
if ( contextLoader instanceof AotContextLoader aotContextLoader ) {
if ( contextLoader instanceof AotContextLoader aotContextLoader ) {
try {
try {
ApplicationContext context = aotContextLoader . loadContextForAotProcessing ( mergedConfig ) ;
ApplicationContext context = aotContextLoader . loadContextForAotProcessing ( mergedConfig ) ;
@ -227,6 +226,14 @@ public class TestContextAotGenerator {
. registerType ( TypeReference . of ( className ) , MemberCategory . INVOKE_PUBLIC_METHODS ) ;
. 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 ) {
private void registerDeclaredConstructors ( Class < ? > type ) {
ReflectionHints reflectionHints = this . runtimeHints . reflection ( ) ;
ReflectionHints reflectionHints = this . runtimeHints . reflection ( ) ;
reflectionHints . registerType ( type , MemberCategory . INVOKE_DECLARED_CONSTRUCTORS ) ;
reflectionHints . registerType ( type , MemberCategory . INVOKE_DECLARED_CONSTRUCTORS ) ;