Skip to content

Commit a83529c

Browse files
Maciej Miklassbrannen
authored andcommitted
Introduce createContext() factory method in AbstractGenericContextLoader
Prior to this commit it was possible to configure the DefaultListableBeanFactory used by the GenericApplicationContext created by AbstractGenericContextLoader, but it was not possible to completely replace the bean factory. This commit introduces a new createContext() factory method in AbstractGenericContextLoader which indirectly allows subclasses to supply a custom DefaultListableBeanFactory implementation to the GenericApplicationContext. Closes gh-25600
1 parent 32e8516 commit a83529c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
112112

113113
validateMergedContextConfiguration(mergedConfig);
114114

115-
GenericApplicationContext context = new GenericApplicationContext();
115+
GenericApplicationContext context = createContext();
116116

117117
ApplicationContext parent = mergedConfig.getParentApplicationContext();
118118
if (parent != null) {
@@ -130,6 +130,15 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
130130
return context;
131131
}
132132

133+
/**
134+
* Creates instance of application context used by this {@code ContextLoader}
135+
*
136+
* @return new Instance of application context
137+
*/
138+
protected GenericApplicationContext createContext() {
139+
return new GenericApplicationContext();
140+
}
141+
133142
/**
134143
* Validate the supplied {@link MergedContextConfiguration} with respect to
135144
* what this context loader supports.
@@ -184,7 +193,7 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
184193
logger.debug(String.format("Loading ApplicationContext for locations [%s].",
185194
StringUtils.arrayToCommaDelimitedString(locations)));
186195
}
187-
GenericApplicationContext context = new GenericApplicationContext();
196+
GenericApplicationContext context = createContext();
188197
prepareContext(context);
189198
customizeBeanFactory(context.getDefaultListableBeanFactory());
190199
createBeanDefinitionReader(context).loadBeanDefinitions(locations);

0 commit comments

Comments
 (0)