Prefer DynamicPropertyRegistar to DynamicPropertyRegistry

Closes gh-41996
This commit is contained in:
Andy Wilkinson
2024-09-25 13:54:43 +01:00
parent fdc4a51e24
commit 3c095b4ec2
18 changed files with 341 additions and 77 deletions

View File

@@ -364,9 +364,9 @@ TIP: You can use the Maven goal `spring-boot:test-run` or the Gradle task `bootT
[[features.dev-services.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`.
This works in a similar way to the xref:testing/testcontainers.adoc#testing.testcontainers.dynamic-properties[`@DynamicPropertySource` annotation] that you can use in your tests.
It allows you to add properties that will become available once your container has started.
If you want to contribute dynamic properties at development time from your `Container` `@Bean` methods, define an additional `DynamicPropertyRegistrar` bean.
The registrar should be defined using a `@Bean` method that injects the container from which the properties will be sourced as a parameter.
This arrangement ensures that container has been started before the properties are used.
A typical configuration would look like this: