Skip to content

Commit 50b20c2

Browse files
committed
Merge branch '5.2.x'
2 parents 1891f8a + d939016 commit 50b20c2

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,7 +70,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
7070
* <ul>
7171
* <li>Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)}
7272
* to allow subclasses to validate the supplied configuration before proceeding.</li>
73-
* <li>Creates a {@link GenericApplicationContext} instance.</li>
73+
* <li>Calls {@link #createContext()} to create a {@link GenericApplicationContext}
74+
* instance.</li>
7475
* <li>If the supplied {@code MergedContextConfiguration} references a
7576
* {@linkplain MergedContextConfiguration#getParent() parent configuration},
7677
* the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
@@ -112,7 +113,7 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
112113

113114
validateMergedContextConfiguration(mergedConfig);
114115

115-
GenericApplicationContext context = new GenericApplicationContext();
116+
GenericApplicationContext context = createContext();
116117

117118
ApplicationContext parent = mergedConfig.getParentApplicationContext();
118119
if (parent != null) {
@@ -150,7 +151,8 @@ protected void validateMergedContextConfiguration(MergedContextConfiguration mer
150151
* <p>Implementation details:
151152
*
152153
* <ul>
153-
* <li>Creates a {@link GenericApplicationContext} instance.</li>
154+
* <li>Calls {@link #createContext()} to create a {@link GenericApplicationContext}
155+
* instance.</li>
154156
* <li>Calls {@link #prepareContext(GenericApplicationContext)} to allow for customizing the context
155157
* before bean definitions are loaded.</li>
156158
* <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the
@@ -184,7 +186,7 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
184186
logger.debug(String.format("Loading ApplicationContext for locations [%s].",
185187
StringUtils.arrayToCommaDelimitedString(locations)));
186188
}
187-
GenericApplicationContext context = new GenericApplicationContext();
189+
GenericApplicationContext context = createContext();
188190
prepareContext(context);
189191
customizeBeanFactory(context.getDefaultListableBeanFactory());
190192
createBeanDefinitionReader(context).loadBeanDefinitions(locations);
@@ -195,6 +197,22 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
195197
return context;
196198
}
197199

200+
/**
201+
* Factory method for creating the {@link GenericApplicationContext} used by
202+
* this {@code ContextLoader}.
203+
*
204+
* <p>The default implementation creates a {@code GenericApplicationContext}
205+
* using the default constructor. This method may be overridden in subclasses
206+
* &mdash; for example, to create a {@code GenericApplicationContext} with
207+
* a custom {@link DefaultListableBeanFactory} implementation.
208+
*
209+
* @return a newly instantiated {@code GenericApplicationContext}
210+
* @since 5.2.9
211+
*/
212+
protected GenericApplicationContext createContext() {
213+
return new GenericApplicationContext();
214+
}
215+
198216
/**
199217
* Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}.
200218
* Called <i>before</i> bean definitions are read.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ protected void loadBeanDefinitions(GenericApplicationContext context, MergedCont
4949
}
5050

5151
/**
52-
* Returns {@code "-context.xml" and "Context.groovy"} in order to
52+
* Returns {@code "-context.xml"} and {@code "Context.groovy"} in order to
5353
* support detection of a default XML config file or Groovy script.
5454
*/
5555
@Override

0 commit comments

Comments
 (0)