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 2076ce7e2dd..0855da245a5 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 @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; +import org.springframework.context.ApplicationContextInitializer; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.lang.Nullable; import org.springframework.test.context.BootstrapContext; @@ -304,8 +305,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", @@ -323,12 +322,13 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot locations.addAll(0, Arrays.asList(processedLocations)); // Legacy ContextLoaders don't know how to process classes } - initializers.addAll(0, Arrays.asList(configAttributes.getInitializers())); if (!configAttributes.isInheritLocations()) { break; } } + Set>> initializers = + ApplicationContextInitializerUtils.resolveInitializerClasses(configAttributesList); Set contextCustomizers = getContextCustomizers(testClass, Collections.unmodifiableList(configAttributesList)); @@ -342,8 +342,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);