20
20
21
21
import org .apache .commons .logging .Log ;
22
22
import org .apache .commons .logging .LogFactory ;
23
+
23
24
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
24
25
import org .springframework .context .ApplicationContext ;
25
26
import org .springframework .context .ConfigurableApplicationContext ;
34
35
import org .springframework .web .context .support .GenericWebApplicationContext ;
35
36
36
37
/**
37
- * TODO [SPR-9864] Document AbstractGenericWebContextLoader.
38
+ * Abstract, generic extension of {@link AbstractContextLoader} that loads a
39
+ * {@link GenericWebApplicationContext}.
40
+ *
41
+ * <p>If instances of concrete subclasses are invoked via the
42
+ * {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}
43
+ * SPI, the context will be loaded from the {@link MergedContextConfiguration}
44
+ * provided to {@link #loadContext(MergedContextConfiguration)}. In such cases, a
45
+ * {@code SmartContextLoader} will decide whether to load the context from
46
+ * <em>locations</em> or <em>annotated classes</em>. Note that {@code
47
+ * AbstractGenericWebContextLoader} does not support the {@code
48
+ * loadContext(String... locations)} method from the legacy
49
+ * {@link org.springframework.test.context.ContextLoader ContextLoader} SPI.
50
+ *
51
+ * <p>Concrete subclasses must provide an appropriate implementation of
52
+ * {@link #loadBeanDefinitions()}.
38
53
*
39
54
* @author Sam Brannen
40
55
* @since 3.2
56
+ * @see #loadContext(MergedContextConfiguration)
57
+ * @see #loadContext(String...)
41
58
*/
42
59
public abstract class AbstractGenericWebContextLoader extends AbstractContextLoader {
43
60
@@ -47,9 +64,33 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
47
64
// --- SmartContextLoader -----------------------------------------------
48
65
49
66
/**
50
- * TODO [SPR-9864] Document overridden loadContext(MergedContextConfiguration).
67
+ * Load a Spring {@link WebApplicationContext} from the supplied
68
+ * {@link MergedContextConfiguration}.
69
+ *
70
+ * <p>Implementation details:
51
71
*
52
- * @see org.springframework.test.context.SmartContextLoader#loadContext(org.springframework.test.context.MergedContextConfiguration)
72
+ * <ul>
73
+ * <li>Creates a {@link GenericWebApplicationContext} instance.</li>
74
+ * <li>Delegates to {@link #configureWebResources()} to create the
75
+ * {@link MockServletContext} and set it in the {@code WebApplicationContext}.</li>
76
+ * <li>Calls {@link #prepareContext()} to allow for customizing the context
77
+ * before bean definitions are loaded.</li>
78
+ * <li>Calls {@link #customizeBeanFactory()} to allow for customizing the
79
+ * context's {@code DefaultListableBeanFactory}.</li>
80
+ * <li>Delegates to {@link #loadBeanDefinitions()} to populate the context
81
+ * from the locations or classes in the supplied {@code MergedContextConfiguration}.</li>
82
+ * <li>Delegates to {@link AnnotationConfigUtils} for
83
+ * {@linkplain AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
84
+ * annotation configuration processors.</li>
85
+ * <li>Calls {@link #customizeContext()} to allow for customizing the context
86
+ * before it is refreshed.</li>
87
+ * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
88
+ * context and registers a JVM shutdown hook for it.</li>
89
+ * </ul>
90
+ *
91
+ * @return a new web application context
92
+ * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
93
+ * @see GenericWebApplicationContext
53
94
*/
54
95
public final ConfigurableApplicationContext loadContext (MergedContextConfiguration mergedConfig ) throws Exception {
55
96
@@ -78,7 +119,29 @@ public final ConfigurableApplicationContext loadContext(MergedContextConfigurati
78
119
}
79
120
80
121
/**
81
- * TODO [SPR-9864] Document configureWebResources().
122
+ * Configures web resources for the supplied web application context.
123
+ *
124
+ * <p>Implementation details:
125
+ *
126
+ * <ul>
127
+ * <li>The resource base path is retrieved from the supplied
128
+ * {@code WebMergedContextConfiguration}.</li>
129
+ * <li>A {@link ResourceLoader} is instantiated for the {@link MockServletContext}:
130
+ * if the resource base path is prefixed with "{@code classpath:}", a
131
+ * {@link DefaultResourceLoader} will be used; otherwise, a
132
+ * {@link FileSystemResourceLoader} will be used.</li>
133
+ * <li>A {@code MockServletContext} will be created using the resource base
134
+ * path and resource loader.</li>
135
+ * <li>The supplied {@link GenericWebApplicationContext} is then stored in
136
+ * the {@code MockServletContext} under the
137
+ * {@link WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE} key.</li>
138
+ * <li>Finally, the {@code MockServletContext} is set in the
139
+ * {@code WebApplicationContext}.</li>
140
+ *
141
+ * @param context the web application context for which to configure the web
142
+ * resources
143
+ * @param webMergedConfig the merged context configuration to use to load the
144
+ * web application context
82
145
*/
83
146
protected void configureWebResources (GenericWebApplicationContext context ,
84
147
WebMergedContextConfiguration webMergedConfig ) {
@@ -93,30 +156,65 @@ protected void configureWebResources(GenericWebApplicationContext context,
93
156
}
94
157
95
158
/**
96
- * TODO [SPR-9864] Document customizeBeanFactory().
159
+ * Customize the internal bean factory of the {@code WebApplicationContext}
160
+ * created by this context loader.
161
+ *
162
+ * <p>The default implementation is empty but can be overridden in subclasses
163
+ * to customize <code>DefaultListableBeanFactory</code>'s standard settings.
164
+ *
165
+ * @param beanFactory the bean factory created by this context loader
166
+ * @param webMergedConfig the merged context configuration to use to load the
167
+ * web application context
168
+ * @see #loadContext(MergedContextConfiguration)
169
+ * @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
170
+ * @see DefaultListableBeanFactory#setAllowEagerClassLoading
171
+ * @see DefaultListableBeanFactory#setAllowCircularReferences
172
+ * @see DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
97
173
*/
98
174
protected void customizeBeanFactory (DefaultListableBeanFactory beanFactory ,
99
175
WebMergedContextConfiguration webMergedConfig ) {
100
176
}
101
177
102
178
/**
103
- * TODO [SPR-9864] Document loadBeanDefinitions().
179
+ * Load bean definitions into the supplied {@link GenericWebApplicationContext context}
180
+ * from the locations or classes in the supplied <code>WebMergedContextConfiguration</code>.
181
+ *
182
+ * <p>Concrete subclasses must provide an appropriate implementation.
183
+ *
184
+ * @param context the context into which the bean definitions should be loaded
185
+ * @param webMergedConfig the merged context configuration to use to load the
186
+ * web application context
187
+ * @see #loadContext(MergedContextConfiguration)
104
188
*/
105
189
protected abstract void loadBeanDefinitions (GenericWebApplicationContext context ,
106
190
WebMergedContextConfiguration webMergedConfig );
107
191
108
192
/**
109
- * TODO [SPR-9864] Document customizeContext().
193
+ * Customize the {@link GenericWebApplicationContext} created by this context
194
+ * loader <i>after</i> bean definitions have been loaded into the context but
195
+ * <i>before</i> the context is refreshed.
196
+ *
197
+ * <p>The default implementation is empty but can be overridden in subclasses
198
+ * to customize the web application context.
199
+ *
200
+ * @param context the newly created web application context
201
+ * @param webMergedConfig the merged context configuration to use to load the
202
+ * web application context
203
+ * @see #loadContext(MergedContextConfiguration)
110
204
*/
111
205
protected void customizeContext (GenericWebApplicationContext context , WebMergedContextConfiguration webMergedConfig ) {
112
206
}
113
207
114
208
// --- ContextLoader -------------------------------------------------------
115
209
116
210
/**
117
- * TODO [SPR-9864] Document overridden loadContext(String...).
211
+ * {@code AbstractGenericWebContextLoader} should be used as a
212
+ * {@link org.springframework.test.context.SmartContextLoader SmartContextLoader},
213
+ * not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}.
214
+ * Consequently, this method is not supported.
118
215
*
119
216
* @see org.springframework.test.context.ContextLoader#loadContext(java.lang.String[])
217
+ * @throws UnsupportedOperationException
120
218
*/
121
219
public final ApplicationContext loadContext (String ... locations ) throws Exception {
122
220
throw new UnsupportedOperationException (
0 commit comments