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
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc
+22Lines changed: 22 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,28 @@ All that is needed to do that is adding javadoc:org.springframework.boot.testcon
47
47
48
48
include-code::importcontainers/MyConfiguration[]
49
49
50
+
== Lifecycle of managed containers
51
+
52
+
If you have used the annotations and extensions provided by Testcontainers framework, then the lifecycle of container instances is managed by the Testcontainers framework.
53
+
Please refer to the official documentation for the information about lifecycle of the containers, when managed by the Testcontainers framework.
54
+
55
+
When the containers are managed by Spring as beans, then the lifecycle is clearly defined by Spring.
56
+
The container beans are created and started before the beans of other types are created.
57
+
This process ensures that any beans, which rely on functionality provided by the containers, can use those functionalities.
58
+
59
+
The test containers can be started multiple times.
60
+
Like any other beans the test containers are created and started once per application context managed by the TestContext Framework.
61
+
For details about how TestContext framework manages the underlying application contexts and beans therein, please refer to the official Spring documentation.
62
+
63
+
The container beans are stopped after the destruction of beans of other types.
64
+
This ensures that any beans depending on the functionalities provided by the containers are cleaned up first.
65
+
66
+
The containers are stopped as part of the application shutdown process, managed by the TestContext framework.
67
+
When the application context gets shutdown, the containers are shutdown as well.
68
+
This usually happens after all tests using that specific cached application context have finished executing, but may happen earlier depending on the caching behavior configured in TestContext Framework.
69
+
70
+
It is important to note that a single test container instance can be, and often is, retained across execution of tests from multiple test classes.
0 commit comments