Browse Source

Introduce createContext() factory method in AbstractWebGenericContextLoader

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 gh-25600
Closes gh-28983
pull/29132/head
Sam Brannen 4 years ago
parent
commit
711820ec70
  1. 7
      spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java
  2. 19
      spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java

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

@ -200,9 +200,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader @@ -200,9 +200,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
* 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
*/

19
spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -114,7 +114,7 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa @@ -114,7 +114,7 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
validateMergedContextConfiguration(webMergedConfig);
GenericWebApplicationContext context = new GenericWebApplicationContext();
GenericWebApplicationContext context = createContext();
ApplicationContext parent = mergedConfig.getParentApplicationContext();
if (parent != null) {
@ -145,6 +145,21 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa @@ -145,6 +145,21 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
// 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 5.2.23
*/
protected GenericWebApplicationContext createContext() {
return new GenericWebApplicationContext();
}
/**
* Configures web resources for the supplied web application context (WAC).
* <h4>Implementation Details</h4>

Loading…
Cancel
Save