Skip to content

Commit

Permalink
Introduce createContext() factory method in AbstractWebGenericContext…
Browse files Browse the repository at this point in the history
…Loader

Prior to this commit it was possible to configure the
DefaultListableBeanFactory used by the GenericWebApplicationContext
created by AbstractWebGenericContextLoader, but it was not possible to
completely replace the bean factory.

This commit introduces a new createContext() factory method in
AbstractWebGenericContextLoader which indirectly allows subclasses to
supply a custom DefaultListableBeanFactory implementation to the
GenericWebApplicationContext.

See spring-projectsgh-25600
Closes spring-projectsgh-28983
  • Loading branch information
sbrannen committed Aug 21, 2022
1 parent 6766c19 commit 812e922
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Expand Up @@ -241,9 +241,10 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
* Factory method for creating the {@link GenericApplicationContext} used by
* this {@code ContextLoader}.
* <p>The default implementation creates a {@code GenericApplicationContext}
* using the default constructor. This method may get overridden e.g. to use
* a custom context subclass or to create a {@code GenericApplicationContext}
* with a custom {@link DefaultListableBeanFactory} implementation.
* using the default constructor. This method may be overridden &mdash; for
* example, to use a custom context subclass or to create a
* {@code GenericApplicationContext} with a custom
* {@link DefaultListableBeanFactory} implementation.
* @return a newly instantiated {@code GenericApplicationContext}
* @since 5.2.9
*/
Expand Down
Expand Up @@ -157,7 +157,7 @@ private final GenericWebApplicationContext loadContext(

validateMergedContextConfiguration(webMergedConfig);

GenericWebApplicationContext context = new GenericWebApplicationContext();
GenericWebApplicationContext context = createContext();

ApplicationContext parent = mergedConfig.getParentApplicationContext();
if (parent != null) {
Expand Down Expand Up @@ -192,6 +192,21 @@ protected void validateMergedContextConfiguration(WebMergedContextConfiguration
// no-op
}

/**
* Factory method for creating the {@link GenericWebApplicationContext} used
* by this {@code ContextLoader}.
* <p>The default implementation creates a {@code GenericWebApplicationContext}
* using the default constructor. This method may be overridden &mdash; for
* example, to use a custom context subclass or to create a
* {@code GenericWebApplicationContext} with a custom
* {@link DefaultListableBeanFactory} implementation.
* @return a newly instantiated {@code GenericWebApplicationContext}
* @since 6.0
*/
protected GenericWebApplicationContext createContext() {
return new GenericWebApplicationContext();
}

/**
* Configures web resources for the supplied web application context (WAC).
* <h4>Implementation Details</h4>
Expand Down

0 comments on commit 812e922

Please sign in to comment.