Merge branch '3.1.x'
Closes gh-38335
This commit is contained in:
@@ -1028,9 +1028,19 @@ If you want to create only a subset of the applicable types, you can use the `ty
|
||||
====
|
||||
|
||||
By default `Container.getDockerImageName()` is used to obtain the name used to find connection details.
|
||||
If you are using a custom docker image, you can use the `name` attribute of `@ServiceConnection` to override it.
|
||||
This works as long as Spring Boot is able to get the instance of the `Container`, which is the case when using a `static` field like in the example above.
|
||||
|
||||
For example, if you have a `GenericContainer` using a Docker image of `registry.mycompany.com/mirror/myredis`, you'd use `@ServiceConnection(name="redis")` to ensure `RedisConnectionDetails` are created.
|
||||
If you're using a `@Bean` method, Spring Boot won't call the bean method to get the Docker image name, because this would cause eager initialization issues.
|
||||
Instead, the return type of the bean method is used to find out which connection detail should be used.
|
||||
This works as long as you're using typed containers, e.g. `Neo4jContainer` or `RabbitMQContainer`.
|
||||
This stops working if you're using `GenericContainer`, e.g. with Redis, as shown in the following example:
|
||||
|
||||
include::code:MyRedisConfiguration[]
|
||||
|
||||
Spring Boot can't tell from `GenericContainer` which container image is used, so the `name` attribute from `@ServiceConnection` must be used to provide that hint.
|
||||
|
||||
You can also can use the `name` attribute of `@ServiceConnection` to override which connection detail will be used, for example when using custom images.
|
||||
If you are using the Docker image `registry.mycompany.com/mirror/myredis`, you'd use `@ServiceConnection(name="redis")` to ensure `RedisConnectionDetails` are created.
|
||||
|
||||
|
||||
|
||||
@@ -1086,6 +1096,8 @@ You can now launch `TestMyApplication` as you would any regular Java `main` meth
|
||||
|
||||
TIP: You can use the Maven goal `spring-boot:test-run` or the Gradle task `bootTestRun` to do this from the command line.
|
||||
|
||||
|
||||
|
||||
[[features.testing.testcontainers.at-development-time.dynamic-properties]]
|
||||
===== Contributing Dynamic Properties at Development Time
|
||||
If you want to contribute dynamic properties at development time from your `Container` `@Bean` methods, you can do so by injecting a `DynamicPropertyRegistry`.
|
||||
|
||||
Reference in New Issue
Block a user