Skip to content

@PropertySource ignoreResourceNotFound throws exception for unresolved placeholder values [SPR-11524] #16149

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions