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

Placeholder resolution within @PropertySource resource locations can not resolve properties from prior sources [SPR-12110] #16726

spring-projects-issues opened this issue Aug 21, 2014 · 1 comment
in: core type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Aug 21, 2014

Eric Sirianni opened SPR-12110 and commented

Consider the following example:


Where is:


And /etc/ is:


ConfigurationClassParser is unable to resolve the config.dir placeholder in the second @PropertySource. The issue is that the resolved PropertySource s are not added to the Environment incrementally, but rather by the parent ConfigurationClassPostProcessor after all PropertySources are resolved:

From ConfigurationClassParser:

for (String location : locations) {
     try {
          String resolvedLocation = this.environment.resolveRequiredPlaceholders(location);
          Resource resource = this.resourceLoader.getResource(resolvedLocation);
          ResourcePropertySource ps = new ResourcePropertySource(resource);
          this.propertySources.add((StringUtils.hasText(name) ? name : ps.getName()), ps);

From ConfigurationClassPostProcessor:

		// Parse each @Configuration class
		ConfigurationClassParser parser = new ConfigurationClassParser(
				this.metadataReaderFactory, this.problemReporter, this.environment,
				this.resourceLoader, this.componentScanBeanNameGenerator, registry);

		// Handle any @PropertySource annotations
		List<PropertySource<?>> parsedPropertySources = parser.getPropertySources();
		if (!parsedPropertySources.isEmpty()) {
			if (!(this.environment instanceof ConfigurableEnvironment)) {
				logger.warn("Ignoring @PropertySource annotations. " +
						"Reason: Environment must implement ConfigurableEnvironment");
			else {
				MutablePropertySources envPropertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();
				for (PropertySource<?> propertySource : parsedPropertySources) {

This code could be restructured to support the use case mentioned above.

Affects: 4.0.6

Issue Links:

  • #16731 PropertySource named cannot be added relative to itself (@PropertySource processing fails)
  • #16727 PropertySources added via @PropertySource aren't available in the environment during component scanning

Referenced from: commits 7c60888

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 21, 2014

Juergen Hoeller commented

This simply wasn't support before, but through a reordering of the processing algorithm, this has been addressed for 4.1 GA now, along with #16726.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: enhancement
None yet

No branches or pull requests

2 participants