Ensures spring.cloud.config.name takes precedence.
spring.cloud.config.name should only default to spring.application.name, not be overridden by it. Fixes gh-1784
This commit is contained in:
@@ -71,9 +71,12 @@ public class ConfigServerConfigDataLocationResolver
|
||||
ConfigClientProperties configClientProperties = binder
|
||||
.bind(ConfigClientProperties.PREFIX, Bindable.of(ConfigClientProperties.class), bindHandler)
|
||||
.orElseGet(ConfigClientProperties::new);
|
||||
String applicationName = binder.bind("spring.application.name", Bindable.of(String.class), bindHandler)
|
||||
.orElse("application");
|
||||
configClientProperties.setName(applicationName);
|
||||
if (!StringUtils.hasText(configClientProperties.getName())) {
|
||||
// default to spring.application.name if name isn't set
|
||||
String applicationName = binder.bind("spring.application.name", Bindable.of(String.class), bindHandler)
|
||||
.orElse("application");
|
||||
configClientProperties.setName(applicationName);
|
||||
}
|
||||
return configClientProperties;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,27 @@ public class ConfigServerConfigDataLocationResolverTests {
|
||||
assertThat(resource.getProfiles()).isEqualTo("myactiveprofile");
|
||||
}
|
||||
|
||||
@Test
|
||||
void configNameDefaultsToApplication() {
|
||||
ConfigServerConfigDataResource resource = testResolveProvileSpecific();
|
||||
assertThat(resource.getProperties().getName()).isEqualTo("application");
|
||||
}
|
||||
|
||||
@Test
|
||||
void configNameDefaultsToSpringApplicationName() {
|
||||
this.environment.setProperty("spring.application.name", "myapp");
|
||||
ConfigServerConfigDataResource resource = testResolveProvileSpecific();
|
||||
assertThat(resource.getProperties().getName()).isEqualTo("myapp");
|
||||
}
|
||||
|
||||
@Test
|
||||
void configNameOverridesSpringApplicationName() {
|
||||
this.environment.setProperty("spring.application.name", "myapp");
|
||||
this.environment.setProperty(ConfigClientProperties.PREFIX + ".name", "myconfigname");
|
||||
ConfigServerConfigDataResource resource = testResolveProvileSpecific();
|
||||
assertThat(resource.getProperties().getName()).isEqualTo("myconfigname");
|
||||
}
|
||||
|
||||
private ConfigServerConfigDataResource testResolveProvileSpecific() {
|
||||
return testResolveProvileSpecific("default");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user