You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot项目中application-default.yaml是否会被加载?

Spring Boot application-default 配置文件额外加载场景

default 是 Spring Boot 内置的特殊默认 Profile,除了主动通过启动参数 -Dspring.profiles.active=default 激活外,还有以下场景会自动加载 application-default.yaml/properties:

  • 未显式激活任何 Profile 时:如果项目启动时没有通过任何渠道指定 spring.profiles.active 的取值,Spring Boot 会默认激活 default Profile,此时 application-default 配置会被自动加载,优先级高于全局主配置 application.yaml。
  • 激活 Profile 列表包含 default 时:不管是在 application.yaml 中配置 spring.profiles.active: develop,default,还是通过环境变量、配置中心等其他渠道指定的激活 Profile 列表包含 default,都会加载对应配置,不需要单独通过启动参数指定。
  • 通过 spring.profiles.include 引入 default 时:无论是主配置还是其他已激活的环境配置中,通过 spring.profiles.include 配置指定包含 default Profile,也会触发该配置文件加载,常用于多 Profile 功能拆分的组合场景。
  • Profile 分组包含 default 时:Spring Boot 2.4+ 支持 Profile 分组能力,如果你配置了类似 spring.profiles.group.prod: prod,default,那么激活 prod 分组时,default 会作为组内 Profile 被自动激活,对应配置也会加载。
  • 单元测试未指定生效 Profile 时:如果单元测试使用 @ActiveProfiles 注解时没有指定任何生效 Profile,或者指定的 Profile 列表包含 default,也会加载该配置文件。

注意:application-default 配置的优先级低于你主动指定的环境专属配置,比如同时激活 prod 和 default 时,同 key 的配置会以 application-prod.yaml 中的取值为准。

内容的提问来源于stack exchange,提问作者Satya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 07:27:01