diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java index ef50582423c..06162f25e41 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java @@ -32,6 +32,7 @@ import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; +import org.springframework.context.ApplicationContextInitializer; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.test.context.BootstrapContext; import org.springframework.test.context.CacheAwareContextLoaderDelegate; @@ -359,8 +360,6 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot ContextLoader contextLoader = resolveContextLoader(testClass, configAttributesList); List locations = new ArrayList<>(); List> classes = new ArrayList<>(); - List> initializers = new ArrayList<>(); - for (ContextConfigurationAttributes configAttributes : configAttributesList) { if (logger.isTraceEnabled()) { logger.trace(String.format("Processing locations and classes for context configuration attributes %s", @@ -384,14 +383,13 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot } // Legacy ContextLoaders don't know how to process classes } - if (configAttributes.getInitializers().length > 0) { - initializers.addAll(0, Arrays.asList(configAttributes.getInitializers())); - } if (!configAttributes.isInheritLocations()) { break; } } + Set>> initializers = + ApplicationContextInitializerUtils.resolveInitializerClasses(configAttributesList); Set contextCustomizers = getContextCustomizers(testClass, Collections.unmodifiableList(configAttributesList)); @@ -405,8 +403,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot TestPropertySourceUtils.buildMergedTestPropertySources(testClass); MergedContextConfiguration mergedConfig = new MergedContextConfiguration(testClass, StringUtils.toStringArray(locations), ClassUtils.toClassArray(classes), - ApplicationContextInitializerUtils.resolveInitializerClasses(configAttributesList), - ActiveProfilesUtils.resolveActiveProfiles(testClass), + initializers, ActiveProfilesUtils.resolveActiveProfiles(testClass), mergedTestPropertySources.getPropertySourceDescriptors(), mergedTestPropertySources.getProperties(), contextCustomizers, contextLoader, cacheAwareContextLoaderDelegate, parentConfig);