Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure direct @PropertySource annotations override meta-annotations #31074

Closed
1 task done
sbrannen opened this issue Aug 18, 2023 · 0 comments
Closed
1 task done

Ensure direct @PropertySource annotations override meta-annotations #31074

sbrannen opened this issue Aug 18, 2023 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Aug 18, 2023

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

  • Ensure direct @PropertySource annotations override meta-annotations.
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Aug 18, 2023
@sbrannen sbrannen added this to the 6.1.0-RC1 milestone Aug 18, 2023
@sbrannen sbrannen self-assigned this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant