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 ignoreResourceNotFound throws exception for unresolved placeholder values [SPR-11524] #16149

Closed
spring-projects-issues opened this issue Mar 7, 2014 · 2 comments
Assignees
Labels
in: core type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 7, 2014

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

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 7, 2014

Juergen Hoeller commented

Good point! As of 4.0.3, we're ignoring placeholder resolution failure as well in case of ignoreResourceNotFound=true.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 7, 2014

Mattias Severson commented

Cheers, keep up the good work!

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.0.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants