Ignore documents that do not apply when checking mandatory locations

Closes gh-24584
pull/24986/head
Madhura Bhave 4 years ago
parent 89f29c933f
commit 615a8ae56e

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -348,8 +348,10 @@ class ConfigDataEnvironment {
ConfigDataActivationContext activationContext) {
Set<ConfigDataLocation> mandatoryLocations = new LinkedHashSet<>();
for (ConfigDataEnvironmentContributor contributor : contributors) {
if (contributor.isActive(activationContext)) {
mandatoryLocations.addAll(getMandatoryImports(contributor));
}
}
for (ConfigDataEnvironmentContributor contributor : contributors) {
if (contributor.getLocation() != null) {
mandatoryLocations.remove(contributor.getLocation());

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -186,6 +186,21 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
assertThat(property).isEqualTo("frompropertiesfile");
}
@Test
void runWhenProfileSpecificMandatoryLocationDoesNotExistShouldNotFail() {
ConfigurableApplicationContext context = this.application.run("--spring.config.name=testprofiles",
"--spring.config.location=classpath:configdata/profiles/");
String property = context.getEnvironment().getProperty("my.property");
assertThat(property).isEqualTo("fromyamlfile");
}
@Test
void runWhenProfileSpecificMandatoryLocationDoesNotExistShouldFailWhenProfileActive() {
this.application.setAdditionalProfiles("prod");
assertThatExceptionOfType(ConfigDataResourceNotFoundException.class).isThrownBy(() -> this.application
.run("--spring.config.name=testprofiles", "--spring.config.location=classpath:configdata/profiles/"));
}
@Test
void runWhenHasActiveProfilesFromMultipleLocationsActivatesProfileFromOneLocation() {
ConfigurableApplicationContext context = this.application

@ -12,4 +12,7 @@ dev:
spring.config.activate.on-profile: other
my:
property: fromotherprofile
---
spring.config.activate.on-profile: prod
spring.config.import: file:./non-existent.yml

Loading…
Cancel
Save