Skip to content

Log failures to load PropertySources when ignoreResourceNotFound = true [SPR-15218] #19783

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

Closed
spring-projects-issues opened this issue Feb 3, 2017 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 3, 2017

Andrew Medworth opened SPR-15218 and commented

In ConfigurationClassParser.processPropertySource(), if ignoreResourceNotFound is set to true for a given property source and that property source is not loadable (e.g. because the file does not exist), no message is currently logged by Spring at any level.

This can make it extremely difficult to debug unexpected behaviour in property source resolution. For example, see the Repro main class in the referenced project on GitHub, which has a PropertySource referring to a non-existent property file.

The ultimate output of this program is myProp = ${mykey}, because the config file is not found and therefore the "mykey" variable substitution does not occur.

However, if the developer was expecting the config file to exist, and hence was surprised at the lack of variable substitution, the cause would be very difficult to diagnose from the application logs, because even at the highest level of logging, there is no message to indicate that Spring tried and failed to open does-not-exist.properties. Of course, real-world scenarios would probably be much more complex.

I propose that Spring's ConfigurationClassParser should be changed to log a message at debug level when a PropertySource with ignoreResourceNotFound = true cannot be loaded for any reason.


Affects: 4.3.6, 5.0 M4

Reference URL: https://github.com/amdw/spring-logging-repro

Issue Links:

Referenced from: pull request #1313, and commits 448ea4c, d6216fb

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Since we're logging an ignore-resource-not-found case for <context:property-placeholder> already, we should definitely do this for @PropertySource as well. Fixed for 4.3.7 now, with a consistent info-level log message in both scenarios.

@spring-projects-issues
Copy link
Collaborator Author

Andrew Medworth commented

Thanks very much - I see this commit on master:

448ea4c

And also this one on the 4.3.x branch:

d6216fb

I really appreciate you addressing this so promptly!

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

2 participants