-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Mattias Severson opened SPR-11524 and commented
Proposal: Spring should silently ignore any unresolved placeholders used in @PropertySource
if the ignoreResourceNotFound
attribute has been set to true
.
Consider the following Java config:
@Configuration
@PropertySources({
@PropertySource("classpath:default.properties"),
@PropertySource(value = "file:${UNKNOWN_PATH}/optional.properties", ignoreResourceNotFound = true),
})
public class TestConfig {
}
The application fetches default properties from default.properties
, but it is also possible to override properties by specifying the UNKNOWN_PATH
environmental variable to point to a folder that contains optional.properties
.
Since the ignoreResourceNotFound
attribute has been set to true
, the optional properties file does not need to be present for the application to start (and this works). However, if the UNKNOWN_PATH
is not specified (neither as a system property, nor as an environmental variable), an exception is currently thrown:
java.lang.IllegalStateException: Failed to load ApplicationContext
[...]
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'UNKNOWN_PATH' in string value "file:${UNKNOWN_PATH}/optional.properties"
[...]
Preferably, Spring should silently ignore that the placeholder cannot be resolved in this case.
Affects: 4.0.2