Introduce ConfigurableApplicationContext.pause() and SmartLifecycle.isPauseable()

Closes gh-35269
This commit is contained in:
Juergen Hoeller
2025-08-01 15:08:15 +02:00
parent 96bc1f50c7
commit 149d468ce4
12 changed files with 191 additions and 53 deletions
@@ -93,8 +93,8 @@ public interface ContextCache {
/**
* Obtain a cached {@link ApplicationContext} for the given key.
* <p>If the cached application context was previously
* {@linkplain org.springframework.context.Lifecycle#stop() stopped}, it
* must be
* {@linkplain org.springframework.context.ConfigurableApplicationContext#pause() paused},
* it must be
* {@linkplain org.springframework.context.support.AbstractApplicationContext#restart()
* restarted}. This applies to parent contexts as well.
* <p>In addition, the {@linkplain #getHitCount() hit} and
@@ -187,7 +187,7 @@ public interface ContextCache {
* {@link MergedContextConfiguration} and any of its parents.
* <p>If no other test classes are actively using the same application
* context(s), the application context(s) should be
* {@linkplain org.springframework.context.Lifecycle#stop() stopped}.
* {@linkplain org.springframework.context.ConfigurableApplicationContext#pause() paused}.
* <p>The default implementation of this method does nothing. Concrete
* implementations are therefore highly encouraged to override this
* method, {@link #registerContextUsage(MergedContextConfiguration, Class)},
@@ -187,7 +187,7 @@ public class DefaultContextCache implements ContextCache {
activeTestClasses.remove(testClass);
if (activeTestClasses.isEmpty()) {
if (context instanceof ConfigurableApplicationContext cac && cac.isRunning()) {
cac.stop();
cac.pause();
}
this.contextUsageMap.remove(mergedConfig);
}