SpringBoot 实践-外部化配置优先级问题

对着背影说爱祢 提交于 2020-01-04 13:33:42

本文主要针对 spring.profiles.activespring.config.location 以及 spring.config.additional-location 的作用机制及优先级问题进行实践对比。

本文案例工程已上传 github 仓库:https://github.com/glmapper/springboot-series-guides/tree/master/guides-properties

spring.profiles.active

除了 application.properties 文件之外,profile-specific 配置也可以通过以下命名方式来定义:application-{profile}.properties。在没有使用 active 指定 profiles 的情况下,Environment 会指定一组默认的 profiles(默认情况下是[default]),换句话说就是,如果没有显示的激活 profiles 配置文件,则默认加载的是 application-default.properties 配置文件。

profile-specific 配置文件的属性与标准 application.properties 从相同的位置加载(一般是 classpath 下);profile-specific 指定的 properties 配置文件始终覆盖默认配置。

在案例工程中(guides-properties),resources 下面包括 application.properties 和 application-dev.properties 两份配置文件

  • application.properties 文件配置
spring.application.name=appNameInner
testKey=key-defa
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!