Springboot Profiles 环境

Active Profile 配置
从上面的分析可以看出指定 profile 的配置优先于默认配置,故可以把与环境无关的配置放在 application.yaml 中,环境相关的配置写在 application-${profile}.yaml 中。其中激活 profile 指定有三种方式:

命令行启动参数设置 --spring.profiles.active={profile}
Java 环境或系统环境变量 spring.profiles.active={profile}
application.yaml 中 spring.profiles.active 配置项
其实这三种都还是通过 Environment 自身的 PropertySource 获取的,分别是 CommandLinePropertySource、SystemEnvironmentPropertySource 和 MapPropertySource#application.yaml。优先级从前到后,命令行指定的 profile 优先级最高,其次是环境变量,最后才是配置文件

参考文档:
https://www.infoq.cn/article/Q-ese4CxV2IWmltsJcGX

原文地址:https://www.cnblogs.com/mengjianzhou/p/11216512.html