Skip to content

DynamicPropertySource is getting initialized way too late in the startup for 'config.import' #26148

@edudar

Description

@edudar

I have ConfigData implementation for a custom KV storage: Loader, LocationResolver, Resource. They are specified in spring.factories under appropriate sections. I also verified that the whole setup works fine when using in an application.

I want to test it though. I use @SpringBootTest for the test and Testcontainers for KV storage setup. @DynamicPropertySource is there quite specifically to address the dynamic nature of ports and other options exposed by Testcontainers so this is what I do:

@Testcontainers
@SpringBootTest(classes = ..., webEnvironment = NONE)
class KVTest {
  @DynamicPropertySource
  static void kvProperties(registry) {
    registry.add("spring.config.import", () -> "kv:" + getConnectionString());
  }
}

When I run the test, I do see that Loader is being created but when ConfigDataEnvironment processes and applies itself, @DynamicPropertySource has not been taken into account yet. Inlined Test Properties are already there but they are not dynamic. As result, anything that might have been added to properties for ConfigData is getting in way too late.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions