Merge branch '4.1.x'

This commit is contained in:
Ryan Baxter
2024-10-02 10:18:59 -04:00
4 changed files with 35 additions and 9 deletions

View File

@@ -30,7 +30,6 @@
<spring-cloud-commons.version>4.2.0-SNAPSHOT</spring-cloud-commons.version>
<aws-java-sdk.version>2.28.13</aws-java-sdk.version>
<google-api-services-iam.version>v1-rev20201112-1.30.10</google-api-services-iam.version>
<testcontainers.version>1.20.1</testcontainers.version>
<wiremock.version>2.35.2</wiremock.version>
<spring-cloud-aws.version>3.2.0</spring-cloud-aws.version>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>

View File

@@ -119,15 +119,25 @@ public class JdbcEnvironmentRepository implements EnvironmentRepository, Ordered
List<String> envs = new ArrayList<>(new LinkedHashSet<>(Arrays.asList(profiles)));
Collections.reverse(applications);
Collections.reverse(envs);
for (String env : envs) {
for (String app : applications) {
addPropertySource(environment, app, env, label);
}
List<String> labels;
if (label.contains(",")) {
labels = Arrays.asList(StringUtils.commaDelimitedListToStringArray(label));
Collections.reverse(labels);
}
// add properties without profile, equivalent to foo.yml, application.yml
if (!configIncomplete) {
for (String app : applications) {
addPropertySource(environment, app, null, label);
else {
labels = Collections.singletonList(label);
}
for (String l : labels) {
for (String env : envs) {
for (String app : applications) {
addPropertySource(environment, app, env, l);
}
}
// add properties without profile, equivalent to foo.yml, application.yml
if (!configIncomplete) {
for (String app : applications) {
addPropertySource(environment, app, null, l);
}
}
}
return environment;

View File

@@ -229,6 +229,22 @@ public class JdbcEnvironmentRepositoryTests {
assertThat(env.getPropertySources().get(1).getSource().get("a.b.c")).isEqualTo("application-bar");
}
@Test
public void testMultipleLabels() {
JdbcEnvironmentProperties properties = new JdbcEnvironmentProperties();
properties.setDefaultLabel("main");
Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(this.dataSource), properties,
new JdbcEnvironmentRepository.PropertiesResultSetExtractor())
.findOne("application", "default", "main,master");
assertThat(env.getName()).isEqualTo("application");
assertThat(env.getProfiles()).isEqualTo(new String[] { "default" });
assertThat(env.getLabel()).isEqualTo("main,master");
assertThat(env.getPropertySources()).isNotEmpty();
assertThat(env.getPropertySources().get(0).getSource().get("a.b.c")).isEqualTo("application-default");
assertThat(env.getPropertySources().get(1).getSource().get("a.b.c")).isEqualTo("application-null");
assertThat(env.getPropertySources().get(2).getSource().get("e.f.g")).isEqualTo("application-default");
}
@ImportAutoConfiguration(SqlInitializationAutoConfiguration.class)
@Configuration(proxyBeanMethods = false)
protected static class ApplicationConfiguration {

View File

@@ -14,3 +14,4 @@ INSERT into MY_PROPERTIES(APPLICATION, PROFILE, LABEL, MY_KEY, MY_VALUE) values
INSERT into PROPERTIES(APPLICATION, PROFILE, LABEL, "KEY", "VALUE") values ('foo', 'bar', 'main', 'a.b.c', 'foo-bar');
INSERT into PROPERTIES(APPLICATION, PROFILE, LABEL, "KEY", "VALUE") values ('application', 'bar', 'main', 'a.b.c', 'application-bar');
INSERT into PROPERTIES(APPLICATION, PROFILE, LABEL, "KEY", "VALUE") values ('application', 'default', 'main', 'e.f.g', 'application-default');