Skip to content

Commit

Permalink
Introduce createContext() factory method in AbstractGenericContextLoader
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Maciej Miklas authored and sbrannen committed Aug 17, 2020
1 parent 32e8516 commit a83529c
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -112,7 +112,7 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati

validateMergedContextConfiguration(mergedConfig);

GenericApplicationContext context = new GenericApplicationContext();
GenericApplicationContext context = createContext();

ApplicationContext parent = mergedConfig.getParentApplicationContext();
if (parent != null) {
Expand All @@ -130,6 +130,15 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
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.
Expand Down Expand Up @@ -184,7 +193,7 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
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);
Expand Down

0 comments on commit a83529c

Please sign in to comment.