aws搭建java项目,java – 禁用Spring Cloud AWS自动配置以进行本地开发

我使用以下Maven依赖项来自动配置所有必要的参数,以使我的项目在AWS上运行:

org.springframework.cloud

spring-cloud-starter-aws

1.2.2.RELEASE

我没有任何关键功能,具体取决于AWS,它只是在运行时从S3加载一些文件.因此,在本地开发(以及测试)期间,我不需要任何AWS自动配置.

我在本地运行时得到的逻辑错误是:

...

Caused by: java.lang.IllegalStateException: There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance

at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]

at org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider.getRegion(Ec2MetadataRegionProvider.java:39) ~[spring-cloud-aws-core-1.2.2.RELEASE.jar:1.2.2.RELEASE]

at org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean.createInstance(AmazonWebserviceClientFactoryBean.java:98) ~[spring-cloud-aws-core-1.2.2.RELEASE.jar:1.2.2.RELEASE]

at org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean.createInstance(AmazonWebserviceClientFactoryBean.java:44) ~[spring-cloud-aws-core-1.2.2.RELEASE.jar:1.2.2.RELEASE]

...

对于测试和本地开发,是否有一个干净,可行的解决方案?

解决方法:

我使用surefire插件为测试解决了这个问题:

org.apache.maven.plugins

maven-surefire-plugin

2.21.0

org.springframework.cloud:spring-cloud-aws-autoconfigure

解决了本地开发,将以下变量设置为VM参数或在Spring Cloud Config Server中:

cloud.aws.region.auto=false

cloud.aws.region.static=us-east-1

您可以使用cloud.aws.region.static的任何值,但必须有一个.

我在不同的地方阅读了这两种解决方案,并认为它可能有助于将来将这些解决方案结合在一起.

标签:java,spring,maven,spring-cloud

来源: https://codeday.me/bug/20190910/1799345.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值