10

如spring 文档spring-cloud-starter-aws-parameter-store-config中所述,我添加了依赖项。现在,对于单元测试,我想禁用参数存储配置。但做不到。

我尝试在 test/application.properties 中设置以下属性

 aws.paramstore.enabled=false

还尝试排除但仍然无法正常工作AwsParamStoreBootstrapConfiguration.classAutoConfiguration

例外

引起:org.springframework.beans.BeanInstantiationException:无法实例化[com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement]:工厂方法'ssmClient'抛出异常;嵌套异常是 com.amazonaws.SdkClientException: Unable to find a region via the region provider chain。必须在构建器或设置环境中提供显式区域以提供区域。在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在 org.springframework.beans.factory。 support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] ...省略了83个常见框架原因:com.amazonaws.SdkClientException:无法通过区域提供者链找到区域。必须在构建器或设置环境中提供显式区域以提供区域。在 com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371) ~[aws-java-sdk-core-1.11.336.jar:na] 在 com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties( AwsClientBuilder.java:337) ~[aws-java-sdk-core-1.11.336.jar:na] at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46) ~[aws-java-sdk -core-1.11.336.jar:na] at com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder.defaultClient(AWSSimpleSystemsManagementClientBuilder.java:44) ~[aws-java-sdk-ssm-1.11.336.jar:na] at org .springframework.cloud.aws.autoconfigure.paramstore.AwsParamStoreBootstrapConfiguration。

4

1 回答 1

17

aws.paramstore.enabled=false通过将属性 ( ) 添加到bootstrap.properties文件测试资源文件夹,我能够使用替代方法禁用 paramstore 。这是一个更简单的解决方案

较旧的解决方案

我能够找出解决方案。似乎甚至在测试配置类之前和加载之前就SpringBootTest尝试加载。解决方案是通过在自身上指定属性来禁用 paramstoressmClientapplication.properties@SpringBootTest

@SpringBootTest(classes = MyApp.class, properties = {"aws.paramstore.enabled=false"})
于 2018-10-31T11:48:44.810 回答