英文:
Load multiple application property files in Springboot
问题
我有以下属性文件。
- application.properties
- application-dev.properties
- application-dev-us1.properties
- application-dev-eu1.properties
我想在dev文件中拥有通用的开发属性,在us1和eu1文件中拥有特定于地区的属性。
我可以通过提供SPRING_ACTIVE_PROFILE环境变量来加载默认和特定的文件属性。但是如何让Spring选择三个文件,即默认、dev和dev-us1呢?
英文:
I have following property files.
- application.properties
- application-dev.properties
- application-dev-us1.properties
- application-dev-eu1.properties
I want to have common dev properties in the dev file and region specific properties in us1 and eu1 files.
I can load default and specific file properties by providing SPRING_ACTIVE_PROFILE environment variable. But how can I make spring pick up three files, default, dev and dev-us1 ?
答案1
得分: 2
你可以通过注入环境变量来实现:-Dspring.profiles.active=dev,dev-eu1
默认情况下会自动选择默认配置文件,而不是其他配置文件。
英文:
You can do it by injecting the env variables: -Dspring.profiles.active=dev,dev-eu1
The default profile is picked up by default amoung the others
答案2
得分: 1
Spring Active Profiles 是复数形式,你可以提供一个配置文件列表,可以作为环境变量,就像其他答案中那样,或者作为注解:
@Profile({"dev", "dev-us1"})
application.properties
文件(默认配置文件)无论如何都会被加载。
英文:
Spring Active Profiles is plural you can provide a list of profiles. Either as an environment variable like in the other answer or as an annotation:
@Profile({"dev", "dev-us1"})
The application.properties
file (= default profile) will be loaded in any case.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论