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

BootstrapConfigFileApplicationListener cant handle optional config locations #1292

Closed
larsgrefer opened this issue Oct 20, 2023 · 4 comments
Closed

Comments

@larsgrefer
Copy link

Describe the bug

BootstrapConfigFileApplicationListener can't handle spring.config.additional-locations with optional: prefixes.

When setting spring.config.additional-location to optional:file:/foo or optional:/bar,

private Set<String> getSearchLocations(String propertyName) {
Set<String> locations = new LinkedHashSet<>();
if (this.environment.containsProperty(propertyName)) {
for (String path : asResolvedSet(this.environment.getProperty(propertyName), null)) {
if (!path.contains("$")) {
path = StringUtils.cleanPath(path);
Assert.state(!path.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX),
"Classpath wildcard patterns cannot be used as a search location");
validateWildcardLocation(path);
if (!ResourceUtils.isUrl(path)) {
path = ResourceUtils.FILE_URL_PREFIX + path;
}
}
locations.add(path);
}
}
return locations;
}
will turn these locations into file:optional:file:/foo and file:optional:/bar.

The following code will then decide that the Resource file:optional:file:/foo/application.properties does not exist, (while file:/foo/application.properties would exist)

if (resource == null || !resource.exists()) {
if (this.logger.isTraceEnabled()) {
StringBuilder description = getDescription("Skipped missing config ", location, resource,
profile);
this.logger.trace(description);
}
continue;
}

This can cause ordering issues between internal and external configuration files, depending on the execution order of BootstrapConfigFileApplicationListener and ConfigDataEnvironmentPostProcessor (so #1213 will hide this problem)

When BootstrapConfigFileApplicationListener runs first, we get this order:

  1. external properties (not found by spring cloud because of this bug)
  2. internal properties (found by BootstrapConfigFileApplicationListener)
  3. external-properties (found by ConfigDataEnvironmentPostProcessor)
  4. internal properties (found by ConfigDataEnvironmentPostProcessor)

When ConfigDataEnvironmentPostProcessor runs first, we get this order:

  1. external-properties (found by ConfigDataEnvironmentPostProcessor)
  2. internal properties (found by ConfigDataEnvironmentPostProcessor)
  3. external properties (not found by spring cloud because of this bug)
  4. internal properties (found by BootstrapConfigFileApplicationListener)

In the first case, the internal properites suddenly get precedence before the external ones.

@ryanjbaxter
Copy link
Contributor

But since #1213 this should no longer matter correct?

@spring-cloud-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@larsgrefer
Copy link
Author

@ryanjbaxter #1213 will hide this, yes

@ryanjbaxter
Copy link
Contributor

After discussing this with the team we view #1213 as a fix for the issue so this can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants