You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document how Testcontainers-managed static containers can be stopped
before Spring's cached application context is closed or reused.
See gh-50210
Signed-off-by: henriquejsza <henriquejsza@gmail.com>
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,11 @@ NOTE: Having containers managed by Testcontainers instead of as Spring beans pro
83
83
It can happen that containers are shutdown before the beans relying on container functionality are cleaned up.
84
84
This can lead to exceptions being thrown by client beans, for example, due to loss of connection.
85
85
86
+
WARNING: When using Testcontainers' JUnit extension with static fields annotated with javadoc:org.testcontainers.junit.jupiter.Container[format=annotation], container instances are stopped after the test class has run.
87
+
Spring's TestContext Framework may cache the javadoc:org.springframework.context.ApplicationContext[] beyond that point and reuse it for another test class with the same configuration.
88
+
If the cached application context contains beans that depend on a container that has already been stopped, later tests or bean destruction callbacks may fail.
89
+
When the application context should remain usable for as long as it is cached, prefer managing containers as Spring beans or importing container declarations with javadoc:org.springframework.boot.testcontainers.context.ImportTestcontainers[format=annotation].
90
+
86
91
Container beans are created and started once per application context managed by Spring's TestContext Framework.
87
92
For details about how TestContext Framework manages the underlying application contexts and beans therein, please refer to the {url-spring-framework-docs}[Spring Framework documentation].
0 commit comments