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

本文主要针对 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 文件配置

你可能感兴趣的:(SpringBoot,核心技术解析与实践系列,spring,boot,spring,后端)