Currently Spring Boot has it's own version of DynamicValuesPropertySource called TestcontainersPropertySource. This class is testcontainers specific and includes some extra functionality, but the basic logic for the core methods is copy/paste from the package-private framework class.

Recently @rwinch has started to reuse TestcontainersPropertySource in the spring-boot-testjars experimental project. This isn't ideal since that project should not depend on spring-boot-testcontainers. We can't move TestcontainersPropertySource and there isn't a good home in Spring Boot to create another public variant so we wondered if the Spring Framework class should be made public instead?

The alternative is to copy/paste the code again into spring-boot-testjars.

Comment From: jhoeller

If I understand that right, Rob would have to copy-and-paste the Testcontainers part of it in any case, so this is primarily about a common base class for that copy?

For a start, we could let DynamicValuesPropertySource extend MapPropertySource (relaxing the latter's generics to Map<String, ?>) so that it just needs to override getProperty. Since getProperty is being customized in TestContainersPropertySource anyway, copying the two common lines of that method from DynamicValuesPropertySource does not seem to be too bad. We could repurpose this issue for such a MapPropertySource-based arrangement in 6.1.4.

Comment From: jhoeller

With this applied, the non-public DynamicValuesPropertySource looks like this, serving as a template for custom copies:

class DynamicValuesPropertySource extends MapPropertySource<Supplier<Object>> {

    DynamicValuesPropertySource(String name, Map<String, Supplier<Object>> valueSuppliers) {
        super(name, valueSuppliers);
    }

    @Override
    public Object getProperty(String name) {
        return SupplierUtils.resolve(this.source.get(name));
    }
}