Currently DynamicPropertyRegistry can be used as a parameter on @Bean methods or test methods annotated with @DynamicPropertySource. If we have a DynamicPropertyContributor type we could return it. This would also allow us to ensure that TestcontainersLifecycleBeanPostProcessor could initialize them early.
The code would look like this:
@Bean
DynamicPropertyContributor dynamicPropertyContributor() {
return (registry) -> {
registry.add("spring.data.redis.host", redis()::getHost);
registry.add("spring.data.redis.port", redis()::getFirstMappedPort);
}
}
Comment From: philwebb
Another option would be to use @DynamicPropertySource on @Configuration classes.
Comment From: snicoll
Less fan of the second option, how would you detect it?
Comment From: philwebb
Detection would be more problematic, but it would be nice not to have to introduce a new public API. I guess we'd need something similar to AutowiredAnnotationBeanPostProcessor to detect them.
The user code would be something like:
@DynamicPropertySource
void dynamicPropertyContributor(DynamicPropertyRegistry registry, GenericContainer<?> redis) {
registry.add("spring.data.redis.host", redis::getHost);
registry.add("spring.data.redis.port", redis::getFirstMappedPort);
}
Comment From: philwebb
We discussed this today and decided we don't like the @DynamicPropertySource annotation option. We prefer the DynamicPropertyContributor idea as it's closer to a Customizer which folks already use.
Comment From: amparab
Hello! @philwebb
I was trying to understand this issue and know how this works. If I am not wrong, do you expect something like below?
@FunctionalInterface
public interface DynamicPropertyContributor {
void contribute(DynamicPropertyRegistry registry);
}
I would be grateful if I could get more of your insights and guidance about how to solve this, I am really keen to do so.
Comment From: philwebb
@amparab We're not 100% sure on the direction we want to take with this issue, it's a bit of a tricky area. I think I should have added the pending-design-work label to indicate that we need more discussion on the issue before we can ask for contributions. Sorry about that, I'll add it now and when we get a clearer view of what we want to do I'll update the issue.