From 9acb5196a4701ccdd602bbe6f2065178b02c5fac Mon Sep 17 00:00:00 2001 From: Tomek Bielecki Date: Tue, 12 Sep 2023 10:38:23 -0700 Subject: [PATCH 1/2] Fixed the order of importing properties --- .../SecretsManagerConfigDataLocationResolver.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLocationResolver.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLocationResolver.java index f65290d19..6f837e91b 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLocationResolver.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLocationResolver.java @@ -24,10 +24,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.springframework.boot.BootstrapContext; -import org.springframework.boot.context.config.ConfigDataLocation; -import org.springframework.boot.context.config.ConfigDataLocationNotFoundException; -import org.springframework.boot.context.config.ConfigDataLocationResolverContext; -import org.springframework.boot.context.config.Profiles; +import org.springframework.boot.context.config.*; import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.logging.DeferredLogFactory; @@ -62,9 +59,9 @@ protected String getPrefix() { } @Override - public List resolveProfileSpecific( - ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, Profiles profiles) - throws ConfigDataLocationNotFoundException { + public List resolve(ConfigDataLocationResolverContext resolverContext, + ConfigDataLocation location) + throws ConfigDataLocationNotFoundException, ConfigDataResourceNotFoundException { registerBean(resolverContext, AwsProperties.class, loadAwsProperties(resolverContext.getBinder())); registerBean(resolverContext, SecretsManagerProperties.class, loadProperties(resolverContext.getBinder())); registerBean(resolverContext, CredentialsProperties.class, From 1239324047799ce952339d0fd4350de80b48e222 Mon Sep 17 00:00:00 2001 From: Tomek Bielecki Date: Mon, 30 Oct 2023 11:04:08 -0700 Subject: [PATCH 2/2] Unit test exposing the config import ordering issue --- ...retsManagerConfigDataLoaderIntegrationTests.java | 13 +++++++++++++ .../src/test/resources/config.properties | 1 + .../src/test/resources/config_second.properties | 1 + 3 files changed, 15 insertions(+) create mode 100644 spring-cloud-aws-autoconfigure/src/test/resources/config.properties create mode 100644 spring-cloud-aws-autoconfigure/src/test/resources/config_second.properties diff --git a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLoaderIntegrationTests.java b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLoaderIntegrationTests.java index 33353c1d6..e38036b06 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLoaderIntegrationTests.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerConfigDataLoaderIntegrationTests.java @@ -46,6 +46,8 @@ import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.PropertySource; +import org.springframework.test.context.TestPropertySource; import org.testcontainers.containers.localstack.LocalStackContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -171,6 +173,17 @@ void resolvesPropertyFromSecretsManager_PlainTextSecret_WithoutSlashes() { } } + @Test + void respectsImportOrder() { + SpringApplication application = new SpringApplication(App.class); + application.setWebApplicationType(WebApplicationType.NONE); + + try (ConfigurableApplicationContext context = runApplication(application, + "classpath:config.properties")) { + assertThat(context.getEnvironment().getProperty("another-parameter")).isEqualTo("from properties file"); + } + } + @Test void clientIsConfiguredWithConfigurerProvidedToBootstrapRegistry() { SpringApplication application = new SpringApplication(App.class); diff --git a/spring-cloud-aws-autoconfigure/src/test/resources/config.properties b/spring-cloud-aws-autoconfigure/src/test/resources/config.properties new file mode 100644 index 000000000..af9b8ad5a --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/test/resources/config.properties @@ -0,0 +1 @@ +spring.config.import=aws-secretsmanager:/config/spring,classpath:config_second.properties diff --git a/spring-cloud-aws-autoconfigure/src/test/resources/config_second.properties b/spring-cloud-aws-autoconfigure/src/test/resources/config_second.properties new file mode 100644 index 000000000..01a949c2b --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/test/resources/config_second.properties @@ -0,0 +1 @@ +another-parameter=from properties file