我有一个工作的spring启动应用程序,包括单元测试。但是当我将amazonsimpleemailservice特性添加到项目中时,spring应用程序可以毫无问题地工作并发送电子邮件,但是单元测试正在运行 mvn clean install
引发异常:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.region.StaticRegionProvider]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: The region '' is not a valid region!
Caused by: java.lang.IllegalArgumentException: The region '' is not a valid region!
请注意,我添加了aws-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aws-context="http://www.springframework.org/schema/cloud/aws/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/cloud/aws/context
http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context-1.0.xsd">
<aws-context:context-credentials>
<aws-context:simple-credentials access-key="${cloud.aws.credentials.accessKey:}" secret-key="${cloud.aws.credentials.secretKey:}"/>
</aws-context:context-credentials>
<aws-context:context-region region="${cloud.aws.region.static:}"/>
</beans>
以及application.yml文件中的配置:
cloud:
aws:
stack:
auto: false
region:
static: us-west-2
auto: false
credentials:
accessKey: __SomeAccessKey__
secretKey: __SomeSecretKey__
有什么想法吗?
1条答案
按热度按时间b5buobof1#
配置区域:与凭据一样,springcloudaws模块还支持在spring引导配置文件中配置区域。区域可以自动检测或显式配置(例如,针对aws云的本地测试)。
cloud.aws.region.auto:真
基于ec2元数据服务启用自动区域检测。因此,在application.yml中设置auto=true。
链接:配置\u区域