java – 禁用Spring Cloud AWS自动配置以进行本地开发
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 禁用Spring Cloud AWS自动配置以进行本地开发,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1974字,纯文字阅读大概需要3分钟。
内容图文
![java – 禁用Spring Cloud AWS自动配置以进行本地开发](/upload/InfoBanner/zyjiaocheng/718/3d8b23e120e24ee2b1d79f99336ead6f.jpg)
我使用以下Maven依赖项来自动配置所有必要的参数,以使我的项目在AWS上运行:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
我没有任何关键功能,具体取决于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插件为测试解决了这个问题:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>org.springframework.cloud:spring-cloud-aws-autoconfigure</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
解决了本地开发,将以下变量设置为VM参数或在Spring Cloud Config Server中:
cloud.aws.region.auto=false
cloud.aws.region.static=us-east-1
您可以使用cloud.aws.region.static的任何值,但必须有一个.
我在不同的地方阅读了这两种解决方案,并认为它可能有助于将来将这些解决方案结合在一起.
内容总结
以上是互联网集市为您收集整理的java – 禁用Spring Cloud AWS自动配置以进行本地开发全部内容,希望文章能够帮你解决java – 禁用Spring Cloud AWS自动配置以进行本地开发所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。