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

@PropertySource locations are being dropped in ConfigurationClassParser processPropertySource [SPR-11637] #16260

Closed
spring-projects-issues opened this issue Mar 31, 2014 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 31, 2014

Russ Tennant opened SPR-11637 and commented

After updating from Spring 3.2.8, property lookup via Environment broke for our projects.

Our projects defined a single property source on our main @Configuration class as follows.

@PropertySource(name="props",
  value={
  "classpath:/path/to/library/defaults.properties",
  "classpath:/path/to/project/defaults.properties",
  "${spring.properties}"
})

Previously, this would result in all three locations being searched in order (reverse) specified.

In Spring 4, only 2 locations are in the CompositePropertySource instead of the expected 3 locations.

It appears the lost location is discarded in ConfigurationClassParser.processPropertySource.

if (!StringUtils.hasText(name) || this.propertySources.containsKey(name)) {
	// We need to ensure unique names when the property source will
	// ultimately end up in a composite
	ResourcePropertySource ps = new ResourcePropertySource(resource);
	this.propertySources.add((StringUtils.hasText(name) ? name : ps.getName()), ps);
}
else {
	this.propertySources.add(name, new ResourcePropertySource(name, resource));
}

It looks like the condition of the ternary operator should match the IF statement.

We have worked around the issue by using multiple @PropertySource annotations.


Affects: 4.0.3

Issue Links:

Referenced from: commits ab24dda, 2187462, bd5b374, 0041e24

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I couldn't reproduce the exact scenario here but I managed to identify a likely potential root cause: In Spring 4.0, for named property sources with multiple values, the first of those values received the specified name but the others had resource-derived names... And the composite property source eventually received the specified name as well, being at odds with the first contained property source

Anyway, I've revised this for consistent naming of contained property sources, avoiding the potential for accidental overriding by name. This will be available in the next 4.0.4 snapshot. Let me know if any problem remains through simply reopening this issue accordingly.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants