简体   繁体   English

如何从 Spring 引导应用程序属性加载 AWS 区域特定属性?

[英]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.至少有几种方法可以处理这个问题。

  1. Use environment variables: Using env variable in Spring Boot's application.properties使用环境变量: 在 Spring Boot 的 application.properties 中使用 env 变量

Feasibly you could structure the names to be something like bucket.name=<bucket-prefix>-${AWS_REGION}可行的是,您可以将名称构造为bucket.name=<bucket-prefix>-${AWS_REGION}

  1. Use Spring profiles.使用 Spring 配置文件。 You can create separate properties files for each region.您可以为每个区域创建单独的属性文件。

For example, you'd have application-us_east_1.properties , application-us_east_2.properties .例如,您将拥有application-us_east_1.propertiesapplication-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.

相关问题 如何在 Spring Boot 应用程序的 application.properties 文件中设置 MyBatis 配置属性? - How do I set MyBatis configuration properties in an application.properties file in a Spring Boot application? Spring Boot:从文件系统加载特定于配置文件的application.properties - Spring boot : load profile specific application.properties from file system 无法在Spring Boot服务中从application.properties加载值 - Cannot load values from application.properties in a spring boot service 从外部文件加载 Spring 引导应用程序属性 - Load Spring Boot application properties from external file Spring Boot - 从依赖的 jar 加载 application.properties/yml - Spring Boot - Load application.properties/yml from dependent jar 从 Spring Boot 中的 application.properties 加载动态对象 - Load dynamic objects from application.properties in Spring Boot 如何在Spring Boot应用程序中使用配置(properties / yml)文件中的属性? - How can I use properties from a configuration (properties/yml) file in my Spring Boot application? 如何从数据库而不是Spring应用程序中的属性文件加载属性 - How to load properties from database instead of properties file in spring application Spring 引导不加载 application.properties - Spring Boot does not load application.properties Spring Boot应用程序不会覆盖特定属性 - Specific properties are not overrided on Spring Boot application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM