[SPR-10325] Allow for ignoreResourceNotFound on @PropertySource Created: 22/Feb/13 Updated: 09/Aug/14 Resolved: 09/Aug/14
|Fix Version/s:||4.0 GA|
|Reporter:||Wesley Hall||Assignee:||Juergen Hoeller|
|Remaining Estimate:||Not Specified|
|Time Spent:||Not Specified|
|Original Estimate:||Not Specified|
|Days since last comment:||5 years, 4 weeks, 6 days ago|
|Last commented by a User:||true|
It doesn't appear to be possible to set up @PropertySource annotations that refer to non-existent files.
It can be quite useful to allow for optional configuration files, for example, ~/.application/application.properties to allow for the optional overriding of configuration properties on a per user basis. I might not have the file, but if I do, it's values should override the defaults.
It is possible to achieve this behaviour with 'setIgnoreResourceNotFound' on the PropertyPlaceholderConfigurer, but the new @PropertySource annotation will throw a FileNotFoudException and the application context fails to start.
Consider adding an attribute to @PropertySource to allow for this behaviour, and potentially a @PropertySources annotation which can be configured with an array of @PropertySource values to allow for file configuration on a per file basis.
|Comment by Robin Sander [ 25/Apr/13 ]|
It's too bad that such a basic usecase isn't supported by Spring out of the box! (I'm using Spring 3.1)
But then I have to ensure that this code gets executed before any other @Configuration instance and until now, I can't find any hint about how to achieve this. At least the order of @Configuration instances seems not to be determined by the @Import annotations (see SPR-10409) and that's why I'm currently injecting BaseConfig in any other @Configuration class to force Spring to initialize this configuration first.