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
This commit is contained in:
Maciej Miklas
2020-08-17 14:10:49 +02:00
committed by Sam Brannen
parent 32e851617e
commit a83529c844

View File

@@ -112,7 +112,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
validateMergedContextConfiguration(mergedConfig);
GenericApplicationContext context = new GenericApplicationContext();
GenericApplicationContext context = createContext();
ApplicationContext parent = mergedConfig.getParentApplicationContext();
if (parent != null) {
@@ -130,6 +130,15 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
return context;
}
/**
* Creates instance of application context used by this {@code ContextLoader}
*
* @return new Instance of application context
*/
protected GenericApplicationContext createContext() {
return new GenericApplicationContext();
}
/**
* Validate the supplied {@link MergedContextConfiguration} with respect to
* what this context loader supports.
@@ -184,7 +193,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
logger.debug(String.format("Loading ApplicationContext for locations [%s].",
StringUtils.arrayToCommaDelimitedString(locations)));
}
GenericApplicationContext context = new GenericApplicationContext();
GenericApplicationContext context = createContext();
prepareContext(context);
customizeBeanFactory(context.getDefaultListableBeanFactory());
createBeanDefinitionReader(context).loadBeanDefinitions(locations);