mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Document semantics of SpringExtension.getApplicationContext()
Since getApplicationContext() was originally not intended to be part of the public API, its Javadoc is intentionally sparse. However, since it is actually a public API used by third parties, this commit improves the documentation for getApplicationContext() by pointing out that invoking the method actually results in the context being eagerly loaded, which may not be desired. This commit also updates the Javadoc for supportsParameter() along the same lines. Closes gh-35764
This commit is contained in:
+15
@@ -334,6 +334,10 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
|
||||
* <li>The parameter is of type {@link ApplicationEvents} or a sub-type thereof.</li>
|
||||
* <li>{@link ParameterResolutionDelegate#isAutowirable} returns {@code true}.</li>
|
||||
* </ol>
|
||||
* <p>This method does not {@linkplain #getApplicationContext(ExtensionContext)
|
||||
* load} the {@code ApplicationContext} or verify that the application context
|
||||
* actually contains a matching candidate bean, since doing so would potentially
|
||||
* load an application context too early or unnecessarily.
|
||||
* <p><strong>WARNING</strong>: If a test class {@code Constructor} is annotated
|
||||
* with {@code @Autowired} or automatically autowirable (see
|
||||
* {@link org.springframework.test.context.TestConstructor @TestConstructor}),
|
||||
@@ -392,6 +396,17 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
|
||||
|
||||
/**
|
||||
* Get the {@link ApplicationContext} associated with the supplied {@link ExtensionContext}.
|
||||
* <p><strong>NOTE</strong>: As of Spring Framework 7.0, the supplied
|
||||
* {@code ExtensionContext} may not be properly <em>scoped</em>. See the
|
||||
* {@linkplain SpringExtension class-level Javadoc} for further details.
|
||||
* <p><strong>WARNING</strong>: Invoking this method ensures that the
|
||||
* corresponding {@code ApplicationContext} is
|
||||
* {@linkplain org.springframework.test.context.TestContext#getApplicationContext()
|
||||
* loaded}. Consequently, this method should not be used if eager loading of
|
||||
* the application context is undesired. For example,
|
||||
* {@link #supportsParameter(ParameterContext, ExtensionContext)} intentionally
|
||||
* does not invoke this method, since doing so would potentially load an
|
||||
* application context too early or unnecessarily.
|
||||
* @param context the current {@code ExtensionContext} (never {@code null})
|
||||
* @return the application context
|
||||
* @throws IllegalStateException if an error occurs while retrieving the application context
|
||||
|
||||
Reference in New Issue
Block a user