diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java index e9373a0026f..747a7f749d1 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java @@ -334,6 +334,10 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes *
  • The parameter is of type {@link ApplicationEvents} or a sub-type thereof.
  • *
  • {@link ParameterResolutionDelegate#isAutowirable} returns {@code true}.
  • * + *

    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. *

    WARNING: 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}. + *

    NOTE: As of Spring Framework 7.0, the supplied + * {@code ExtensionContext} may not be properly scoped. See the + * {@linkplain SpringExtension class-level Javadoc} for further details. + *

    WARNING: 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