@@ -64,9 +64,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
64
64
65
65
/**
66
66
* Load a Spring ApplicationContext from the supplied {@link MergedContextConfiguration}.
67
- *
68
67
* <p>Implementation details:
69
- *
70
68
* <ul>
71
69
* <li>Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)}
72
70
* to allow subclasses to validate the supplied configuration before proceeding.</li>
@@ -98,7 +96,6 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
98
96
* <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
99
97
* context and registers a JVM shutdown hook for it.</li>
100
98
* </ul>
101
- *
102
99
* @return a new application context
103
100
* @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
104
101
* @see GenericApplicationContext
@@ -108,26 +105,28 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
108
105
public final ConfigurableApplicationContext loadContext (MergedContextConfiguration mergedConfig ) throws Exception {
109
106
if (logger .isDebugEnabled ()) {
110
107
logger .debug (String .format ("Loading ApplicationContext for merged context configuration [%s]." ,
111
- mergedConfig ));
108
+ mergedConfig ));
112
109
}
113
110
114
111
validateMergedContextConfiguration (mergedConfig );
115
112
116
113
GenericApplicationContext context = createContext ();
117
-
118
114
ApplicationContext parent = mergedConfig .getParentApplicationContext ();
119
115
if (parent != null ) {
120
116
context .setParent (parent );
121
117
}
118
+
122
119
prepareContext (context );
123
120
prepareContext (context , mergedConfig );
124
121
customizeBeanFactory (context .getDefaultListableBeanFactory ());
125
122
loadBeanDefinitions (context , mergedConfig );
126
123
AnnotationConfigUtils .registerAnnotationConfigProcessors (context );
127
124
customizeContext (context );
128
125
customizeContext (context , mergedConfig );
126
+
129
127
context .refresh ();
130
128
context .registerShutdownHook ();
129
+
131
130
return context ;
132
131
}
133
132
@@ -147,9 +146,7 @@ protected void validateMergedContextConfiguration(MergedContextConfiguration mer
147
146
148
147
/**
149
148
* Load a Spring ApplicationContext from the supplied {@code locations}.
150
- *
151
149
* <p>Implementation details:
152
- *
153
150
* <ul>
154
151
* <li>Calls {@link #createContext()} to create a {@link GenericApplicationContext}
155
152
* instance.</li>
@@ -168,12 +165,10 @@ protected void validateMergedContextConfiguration(MergedContextConfiguration mer
168
165
* <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
169
166
* context and registers a JVM shutdown hook for it.</li>
170
167
* </ul>
171
- *
172
168
* <p><b>Note</b>: this method does not provide a means to set active bean definition
173
169
* profiles for the loaded context. See {@link #loadContext(MergedContextConfiguration)}
174
170
* and {@link AbstractContextLoader#prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)}
175
171
* for an alternative.
176
- *
177
172
* @return a new application context
178
173
* @see org.springframework.test.context.ContextLoader#loadContext
179
174
* @see GenericApplicationContext
@@ -184,28 +179,30 @@ protected void validateMergedContextConfiguration(MergedContextConfiguration mer
184
179
public final ConfigurableApplicationContext loadContext (String ... locations ) throws Exception {
185
180
if (logger .isDebugEnabled ()) {
186
181
logger .debug (String .format ("Loading ApplicationContext for locations [%s]." ,
187
- StringUtils .arrayToCommaDelimitedString (locations )));
182
+ StringUtils .arrayToCommaDelimitedString (locations )));
188
183
}
184
+
189
185
GenericApplicationContext context = createContext ();
186
+
190
187
prepareContext (context );
191
188
customizeBeanFactory (context .getDefaultListableBeanFactory ());
192
189
createBeanDefinitionReader (context ).loadBeanDefinitions (locations );
193
190
AnnotationConfigUtils .registerAnnotationConfigProcessors (context );
194
191
customizeContext (context );
192
+
195
193
context .refresh ();
196
194
context .registerShutdownHook ();
195
+
197
196
return context ;
198
197
}
199
198
200
199
/**
201
200
* Factory method for creating the {@link GenericApplicationContext} used by
202
201
* this {@code ContextLoader}.
203
- *
204
202
* <p>The default implementation creates a {@code GenericApplicationContext}
205
203
* using the default constructor. This method may be overridden in subclasses
206
204
* — for example, to create a {@code GenericApplicationContext} with
207
205
* a custom {@link DefaultListableBeanFactory} implementation.
208
- *
209
206
* @return a newly instantiated {@code GenericApplicationContext}
210
207
* @since 5.2.9
211
208
*/
@@ -216,10 +213,8 @@ protected GenericApplicationContext createContext() {
216
213
/**
217
214
* Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}.
218
215
* Called <i>before</i> bean definitions are read.
219
- *
220
216
* <p>The default implementation is empty. Can be overridden in subclasses to
221
217
* customize {@code GenericApplicationContext}'s standard settings.
222
- *
223
218
* @param context the context that should be prepared
224
219
* @since 2.5
225
220
* @see #loadContext(MergedContextConfiguration)
@@ -235,10 +230,8 @@ protected void prepareContext(GenericApplicationContext context) {
235
230
/**
236
231
* Customize the internal bean factory of the ApplicationContext created by
237
232
* this {@code ContextLoader}.
238
- *
239
233
* <p>The default implementation is empty but can be overridden in subclasses
240
234
* to customize {@code DefaultListableBeanFactory}'s standard settings.
241
- *
242
235
* @param beanFactory the bean factory created by this {@code ContextLoader}
243
236
* @since 2.5
244
237
* @see #loadContext(MergedContextConfiguration)
@@ -254,18 +247,15 @@ protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
254
247
/**
255
248
* Load bean definitions into the supplied {@link GenericApplicationContext context}
256
249
* from the locations or classes in the supplied {@code MergedContextConfiguration}.
257
- *
258
250
* <p>The default implementation delegates to the {@link BeanDefinitionReader}
259
251
* returned by {@link #createBeanDefinitionReader(GenericApplicationContext)} to
260
252
* {@link BeanDefinitionReader#loadBeanDefinitions(String) load} the
261
253
* bean definitions.
262
- *
263
254
* <p>Subclasses must provide an appropriate implementation of
264
255
* {@link #createBeanDefinitionReader(GenericApplicationContext)}. Alternatively subclasses
265
256
* may provide a <em>no-op</em> implementation of {@code createBeanDefinitionReader()}
266
257
* and override this method to provide a custom strategy for loading or
267
258
* registering bean definitions.
268
- *
269
259
* @param context the context into which the bean definitions should be loaded
270
260
* @param mergedConfig the merged context configuration
271
261
* @since 3.1
@@ -278,7 +268,6 @@ protected void loadBeanDefinitions(GenericApplicationContext context, MergedCont
278
268
/**
279
269
* Factory method for creating a new {@link BeanDefinitionReader} for loading
280
270
* bean definitions into the supplied {@link GenericApplicationContext context}.
281
- *
282
271
* @param context the context for which the {@code BeanDefinitionReader}
283
272
* should be created
284
273
* @return a {@code BeanDefinitionReader} for the supplied context
@@ -293,10 +282,8 @@ protected void loadBeanDefinitions(GenericApplicationContext context, MergedCont
293
282
* Customize the {@link GenericApplicationContext} created by this
294
283
* {@code ContextLoader} <i>after</i> bean definitions have been
295
284
* loaded into the context but <i>before</i> the context is refreshed.
296
- *
297
285
* <p>The default implementation is empty but can be overridden in subclasses
298
286
* to customize the application context.
299
- *
300
287
* @param context the newly created application context
301
288
* @since 2.5
302
289
* @see #loadContext(MergedContextConfiguration)
0 commit comments