1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -70,7 +70,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
70
70
* <ul>
71
71
* <li>Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)}
72
72
* 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>
74
75
* <li>If the supplied {@code MergedContextConfiguration} references a
75
76
* {@linkplain MergedContextConfiguration#getParent() parent configuration},
76
77
* the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
@@ -112,7 +113,7 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
112
113
113
114
validateMergedContextConfiguration (mergedConfig );
114
115
115
- GenericApplicationContext context = new GenericApplicationContext ();
116
+ GenericApplicationContext context = createContext ();
116
117
117
118
ApplicationContext parent = mergedConfig .getParentApplicationContext ();
118
119
if (parent != null ) {
@@ -150,7 +151,8 @@ protected void validateMergedContextConfiguration(MergedContextConfiguration mer
150
151
* <p>Implementation details:
151
152
*
152
153
* <ul>
153
- * <li>Creates a {@link GenericApplicationContext} instance.</li>
154
+ * <li>Calls {@link #createContext()} to create a {@link GenericApplicationContext}
155
+ * instance.</li>
154
156
* <li>Calls {@link #prepareContext(GenericApplicationContext)} to allow for customizing the context
155
157
* before bean definitions are loaded.</li>
156
158
* <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the
@@ -184,7 +186,7 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
184
186
logger .debug (String .format ("Loading ApplicationContext for locations [%s]." ,
185
187
StringUtils .arrayToCommaDelimitedString (locations )));
186
188
}
187
- GenericApplicationContext context = new GenericApplicationContext ();
189
+ GenericApplicationContext context = createContext ();
188
190
prepareContext (context );
189
191
customizeBeanFactory (context .getDefaultListableBeanFactory ());
190
192
createBeanDefinitionReader (context ).loadBeanDefinitions (locations );
@@ -195,6 +197,22 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
195
197
return context ;
196
198
}
197
199
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
+ * — 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
+
198
216
/**
199
217
* Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}.
200
218
* Called <i>before</i> bean definitions are read.
0 commit comments