20
20
import org .springframework .lang .Nullable ;
21
21
22
22
/**
23
- * Strategy interface for loading an {@link ApplicationContext application context}
24
- * for an integration test managed by the Spring TestContext Framework.
23
+ * Strategy interface for loading an {@link ApplicationContext} for an integration
24
+ * test managed by the Spring TestContext Framework.
25
25
*
26
26
* <p>The {@code SmartContextLoader} SPI supersedes the {@link ContextLoader} SPI
27
27
* introduced in Spring 2.5: a {@code SmartContextLoader} can choose to process
28
- * either resource locations or annotated classes. Furthermore, a
29
- * {@code SmartContextLoader} can set active bean definition profiles in the
30
- * context that it loads (see {@link MergedContextConfiguration#getActiveProfiles()}
31
- * and {@link #loadContext(MergedContextConfiguration)}).
28
+ * resource locations, annotated classes, or a combination of both. Furthermore, a
29
+ * {@code SmartContextLoader} can configure the context that it
30
+ * {@linkplain #loadContext(MergedContextConfiguration) loads} based on any
31
+ * properties available in the provided {@link MergedContextConfiguration}. For
32
+ * example, active bean definition profiles can be configured for the context
33
+ * based on {@link MergedContextConfiguration#getActiveProfiles()}.
32
34
*
33
35
* <p>See the Javadoc for {@link ContextConfiguration @ContextConfiguration}
34
36
* for a definition of <em>annotated class</em>.
45
47
* hierarchy of the root test class and then supplied to
46
48
* {@link #loadContext(MergedContextConfiguration) loadContext()}.
47
49
*
48
- * <p>Even though {@code SmartContextLoader} extends {@code ContextLoader},
49
- * clients should favor {@code SmartContextLoader}-specific methods over those
50
- * defined in {@code ContextLoader}, particularly because a
51
- * {@code SmartContextLoader} may choose not to support methods defined in the
52
- * {@code ContextLoader} SPI.
50
+ * <p>NOTE: As of Spring Framework 6.0, {@code SmartContextLoader} no longer
51
+ * supports methods defined in the {@code ContextLoader} SPI.
53
52
*
54
53
* <p>Concrete implementations must provide a {@code public} no-args constructor.
55
54
*
58
57
* <li>{@link org.springframework.test.context.support.DelegatingSmartContextLoader DelegatingSmartContextLoader}</li>
59
58
* <li>{@link org.springframework.test.context.support.AnnotationConfigContextLoader AnnotationConfigContextLoader}</li>
60
59
* <li>{@link org.springframework.test.context.support.GenericXmlContextLoader GenericXmlContextLoader}</li>
60
+ * <li>{@link org.springframework.test.context.support.GenericGroovyXmlContextLoader GenericGroovyXmlContextLoader}</li>
61
61
* <li>{@link org.springframework.test.context.web.WebDelegatingSmartContextLoader WebDelegatingSmartContextLoader}</li>
62
62
* <li>{@link org.springframework.test.context.web.AnnotationConfigWebContextLoader AnnotationConfigWebContextLoader}</li>
63
63
* <li>{@link org.springframework.test.context.web.GenericXmlWebContextLoader GenericXmlWebContextLoader}</li>
64
+ * <li>{@link org.springframework.test.context.web.GenericGroovyXmlWebContextLoader GenericGroovyXmlWebContextLoader}</li>
64
65
* </ul>
65
66
*
66
67
* @author Sam Brannen
67
68
* @since 3.1
68
69
* @see ContextConfiguration
69
70
* @see ActiveProfiles
71
+ * @see TestPropertySource
70
72
* @see ContextConfigurationAttributes
71
73
* @see MergedContextConfiguration
72
74
*/
73
75
public interface SmartContextLoader extends ContextLoader {
74
76
75
77
/**
76
- * Processes the {@link ContextConfigurationAttributes} for a given test class.
78
+ * Process the {@link ContextConfigurationAttributes} for a given test class.
77
79
* <p>Concrete implementations may choose to <em>modify</em> the {@code locations}
78
- * or {@code classes} in the supplied {@link ContextConfigurationAttributes},
80
+ * or {@code classes} in the supplied {@code ContextConfigurationAttributes},
79
81
* <em>generate</em> default configuration locations, or <em>detect</em>
80
82
* default configuration classes if the supplied values are {@code null}
81
83
* or empty.
82
- * <p><b>Note</b>: in contrast to a standard {@code ContextLoader}, a
83
- * {@code SmartContextLoader} <b>must</b> <em>preemptively</em> verify that
84
- * a generated or detected default actually exists before setting the corresponding
85
- * {@code locations} or {@code classes} property in the supplied
86
- * {@link ContextConfigurationAttributes}. Consequently, leaving the
87
- * {@code locations} or {@code classes} property empty signals that
88
- * this {@code SmartContextLoader} was not able to generate or detect defaults.
84
+ * <p><b>Note</b>: a {@code SmartContextLoader} must <em>preemptively</em>
85
+ * verify that a generated or detected default actually exists before setting
86
+ * the corresponding {@code locations} or {@code classes} property in the
87
+ * supplied {@code ContextConfigurationAttributes}. Consequently, leaving the
88
+ * {@code locations} or {@code classes} property empty signals that this
89
+ * {@code SmartContextLoader} was not able to generate or detect defaults.
89
90
* @param configAttributes the context configuration attributes to process
90
91
*/
91
92
void processContextConfiguration (ContextConfigurationAttributes configAttributes );
92
93
93
94
/**
94
- * Loads a new {@link ApplicationContext context} based on the supplied
95
+ * Load a new {@linkplain ApplicationContext context} based on the supplied
95
96
* {@link MergedContextConfiguration merged context configuration},
96
- * configures the context, and finally returns the context in a fully
97
- * <em>refreshed</em> state.
97
+ * configure the context, and return the context in a fully <em>refreshed</em>
98
+ * state.
98
99
* <p>Concrete implementations should register annotation configuration
99
100
* processors with bean factories of
100
101
* {@link ApplicationContext application contexts} loaded by this
@@ -103,22 +104,35 @@ public interface SmartContextLoader extends ContextLoader {
103
104
* {@link org.springframework.beans.factory.annotation.Autowired @Autowired},
104
105
* {@link jakarta.annotation.Resource @Resource}, and
105
106
* {@link jakarta.inject.Inject @Inject}. In addition, concrete implementations
106
- * should set the active bean definition profiles in the context's
107
- * {@link org.springframework.core.env.Environment Environment}.
108
- * <p>Any {@code ApplicationContext} loaded by a
109
- * {@code SmartContextLoader} <strong>must</strong> register a JVM
110
- * shutdown hook for itself. Unless the context gets closed early, all context
111
- * instances will be automatically closed on JVM shutdown. This allows for
112
- * freeing of external resources held by beans within the context (e.g.,
113
- * temporary files).
107
+ * should perform the following actions.
108
+ * <ul>
109
+ * <li>Set the parent {@code ApplicationContext} if appropriate (see
110
+ * {@link MergedContextConfiguration#getParent()}).</li>
111
+ * <li>Set the active bean definition profiles in the context's
112
+ * {@link org.springframework.core.env.Environment Environment} (see
113
+ * {@link MergedContextConfiguration#getActiveProfiles()}).</li>
114
+ * <li>Add test {@link org.springframework.core.env.PropertySource PropertySources}
115
+ * to the {@code Environment} (see
116
+ * {@link MergedContextConfiguration#getPropertySourceLocations()},
117
+ * {@link MergedContextConfiguration#getPropertySourceProperties()}, and
118
+ * {@link org.springframework.test.context.support.TestPropertySourceUtils
119
+ * TestPropertySourceUtils}).</li>
120
+ * <li>Invoke {@link org.springframework.context.ApplicationContextInitializer
121
+ * ApplicationContextInitializers} (see
122
+ * {@link MergedContextConfiguration#getContextInitializerClasses()}).</li>
123
+ * <li>Invoke {@link ContextCustomizer ContextCustomizers} (see
124
+ * {@link MergedContextConfiguration#getContextCustomizers()}).</li>
125
+ * <li>Register a JVM shutdown hook for the {@link ApplicationContext}. Unless
126
+ * the context gets closed early, all context instances will be automatically
127
+ * closed on JVM shutdown. This allows for freeing of external resources held
128
+ * by beans within the context — for example, temporary files.</li>
129
+ * </ul>
114
130
* @param mergedConfig the merged context configuration to use to load the
115
131
* application context
116
132
* @return a new application context
117
133
* @throws Exception if context loading failed
118
134
* @see #processContextConfiguration(ContextConfigurationAttributes)
119
- * @see org.springframework.context.annotation.AnnotationConfigUtils
120
- * #registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry)
121
- * @see MergedContextConfiguration#getActiveProfiles()
135
+ * @see org.springframework.context.annotation.AnnotationConfigUtils#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry)
122
136
* @see org.springframework.context.ConfigurableApplicationContext#getEnvironment()
123
137
*/
124
138
ApplicationContext loadContext (MergedContextConfiguration mergedConfig ) throws Exception ;
0 commit comments