mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Resolve context initializers only once in AbstractTestContextBootstrapper
The internal buildMergedContextConfiguration() method in
AbstractTestContextBootstrapper originally resolved the
ApplicationContextInitializer set only once. However, the changes made
in commit 2244461778 introduced a regression resulting in the
initializers being resolved twice: once for validation and once for
actually building the merged context configuration. In addition, the
resolution for validation does not honor the inheritInitializers flag
in ContextConfigurationAttributes.
To address these issues, buildMergedContextConfiguration() once again
resolves the context initializers once via
ApplicationContextInitializerUtils.resolveInitializerClasses().
See gh-18528
Closes gh-36430
This commit is contained in:
+4
-7
@@ -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<String> locations = new ArrayList<>();
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
List<Class<?>> 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<Class<? extends ApplicationContextInitializer<?>>> initializers =
|
||||
ApplicationContextInitializerUtils.resolveInitializerClasses(configAttributesList);
|
||||
Set<ContextCustomizer> 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);
|
||||
|
||||
Reference in New Issue
Block a user