[英]How do I load AWS region specific properties from Spring Boot application properties?
My java microservice (developed in Spring boot) loads S3 bucket from an application properties file.我的 java 微服务(在 Spring 引导中开发)从应用程序属性文件加载 S3 存储桶。 S3 bucket names for 4 different AWS regions are different (bucker-east-1, bucker-west-2 etc) hence how do I load AWS region-specific properties from application properties? 4 个不同 AWS 区域的 S3 存储桶名称不同(bucker-east-1、bucker-west-2 等),因此如何从应用程序属性加载 AWS 区域特定的属性? For example, for us-west-2 region, bucker-us-west-2 property should be loaded, etc. is there any existing support for this type of feature in SPring boot?例如,对于 us-west-2 区域,应加载 bucker-us-west-2 属性等。在 SPring 引导中是否存在对此类功能的任何支持?
There's at least a couple of ways you could handle this.至少有几种方法可以处理这个问题。
Feasibly you could structure the names to be something like bucket.name=<bucket-prefix>-${AWS_REGION}
可行的是,您可以将名称构造为bucket.name=<bucket-prefix>-${AWS_REGION}
For example, you'd have application-us_east_1.properties
, application-us_east_2.properties
.例如,您将拥有application-us_east_1.properties
、 application-us_east_2.properties
。 You then can add the appropriate spring profile upon deployment by passing in the JVM parameter, -Dspring.profiles.active=us_east_1
to activate us_east_1.然后,您可以在部署时添加适当的 spring 配置文件,方法是传入 JVM 参数-Dspring.profiles.active=us_east_1
以激活 us_east_1。 Alternatively, you can use the SPRING_PROFILES_ACTIVE environment variable similarly.或者,您可以类似地使用 SPRING_PROFILES_ACTIVE 环境变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.