Overview

Although the work performed in conjunction with #30941 ensures that all @PropertySource annotations are found, we still have an issue with the semantics of property source overrides.

Ideally, a @PropertySource declared closer to (or directly on) an @Configuration class should override any @PropertySource annotation present as a meta-annotation on the @Configuration class.

Note that the search algorithm for @TestPropertySource already supports those semantics.

Example

With the status quo, the following test fails, because P1 is registered with higher precedence than P2.

@SpringJUnitConfig
class PropertySourceTests {

    @Test
    void test(@Autowired ConfigurableEnvironment env) {
        Stream<String> properySourceNames = this.env.getPropertySources().stream()
                .map(org.springframework.core.env.PropertySource::getName);
        // All properties files should be found,
        // and P2 should have higher precedence than P1.
        assertThat(properySourceNames)
                .containsExactly("systemProperties", "systemEnvironment", "P2", "P1");
    }


    @Retention(RetentionPolicy.RUNTIME)
    @PropertySource(value = "/example/p1.properties", name = "P1")
    @interface PropertySource1 {
    }

    @Configuration
    @PropertySource1
    @PropertySource(value = "/example/p2.properties", name = "P2")
    static class Config {
    }

}

Deliverables

  • [x] Ensure direct @PropertySource annotations override meta-annotations.