From c6a99adbabfe2dcd7d677caa4ee8e6ea194cd41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20D=C4=85browski?= <3007876+marcindabrowski@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:52:42 +0200 Subject: [PATCH] Fix `AutoConfigureAfter` for `SecretsManagerAutoConfiguration` (#1235) Fixes #1232 --- .../SecretsManagerAutoConfiguration.java | 8 ++-- .../core/AwsAutoConfiguration.java | 2 + .../core/AwsAutoConfigurationTests.java | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfigurationTests.java diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerAutoConfiguration.java index 64b22e8d9..9edaabad5 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/config/secretsmanager/SecretsManagerAutoConfiguration.java @@ -15,15 +15,13 @@ */ package io.awspring.cloud.autoconfigure.config.secretsmanager; +import io.awspring.cloud.autoconfigure.core.AwsAutoConfiguration; import io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer; import io.awspring.cloud.autoconfigure.core.AwsClientCustomizer; import io.awspring.cloud.autoconfigure.core.AwsConnectionDetails; -import io.awspring.cloud.autoconfigure.core.CredentialsProviderAutoConfiguration; -import io.awspring.cloud.autoconfigure.core.RegionProviderAutoConfiguration; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -33,7 +31,7 @@ import software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder; /** - * {@link EnableAutoConfiguration Auto-Configuration} for Secrets Manager integration. + * {@link AutoConfiguration Auto-Configuration} for Secrets Manager integration. * * @author Maciej Walkowiak * @since 3.2.0 @@ -41,7 +39,7 @@ @AutoConfiguration @EnableConfigurationProperties(SecretsManagerProperties.class) @ConditionalOnClass({ SecretsManagerClient.class }) -@AutoConfigureAfter({ CredentialsProviderAutoConfiguration.class, RegionProviderAutoConfiguration.class }) +@AutoConfigureAfter(AwsAutoConfiguration.class) @ConditionalOnProperty(name = "spring.cloud.aws.secretsmanager.enabled", havingValue = "true", matchIfMissing = true) public class SecretsManagerAutoConfiguration { diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfiguration.java index 63f86ed8a..0bfd3c233 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfiguration.java @@ -16,6 +16,7 @@ package io.awspring.cloud.autoconfigure.core; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; @@ -28,6 +29,7 @@ * @since 3.0 */ @AutoConfiguration +@AutoConfigureAfter({ CredentialsProviderAutoConfiguration.class, RegionProviderAutoConfiguration.class }) @EnableConfigurationProperties(AwsProperties.class) public class AwsAutoConfiguration { diff --git a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfigurationTests.java b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfigurationTests.java new file mode 100644 index 000000000..fa6fdaab7 --- /dev/null +++ b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/core/AwsAutoConfigurationTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.awspring.cloud.autoconfigure.core; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link AwsAutoConfiguration}. + * + * @author Marcin DÄ…browski + */ +class AwsAutoConfigurationTests { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withPropertyValues("spring.cloud.aws.region.static:eu-west-1") + .withConfiguration(AutoConfigurations.of(AwsAutoConfiguration.class, + CredentialsProviderAutoConfiguration.class, RegionProviderAutoConfiguration.class)); + + @Test + void createsAwsClientBuilderConfigurerBeanByDefault() { + this.contextRunner.run(context -> assertThat(context).hasSingleBean(AwsClientBuilderConfigurer.class)); + } +}