Multiple properties file for a single spring profile

前端 未结 4 543
广开言路
广开言路 2020-12-20 06:53

We are using spring boot 2.0.0. We have three environments dev, staging, production. Our current config structure

4条回答
  •  情深已故
    2020-12-20 07:12

    I think there are 2 ways you can achieve this requirement.

    spring.profiles.active accepts a comma-separated list of active profiles, so you can always provide dev,dev-sqs,dev-redis as the value.

    Another approach is by making use of @PropertySource and a custom PropertySourceFactory to achieve this requirement. You can find an implementation which takes the value from spring.profiles.active to load one corresponding YAML file in the article below. It should be super easy to adapt the implementation to load multiple files by looking for the profile id in the name of the YAML files.

    [How-to] Read profile-based YAML configurations with @PropertySource

提交回复
热议问题