【发布时间】:2021-06-12 20:06:17
【问题描述】:
我正在将应用程序从 Spring Boot 2.3 迁移到 Spring Boot 2.4,我在加载配置文件时遇到了一些问题。
在我的应用程序中,我有一些个人资料:
- default (application-default.yml) :应用程序的默认值。有很多默认值,目的是不让文件 application.yml 复杂化,所以有这个文件很重要
- 质量(application-quality.yml):质量概况
- 环境配置文件(例如application-Dev.yml):当前环境的配置文件。它必须覆盖 application.yml 和 application-default.yml 值
- 环境的数据库配置文件(例如 application-databaseDev.yml):当前环境的数据库连接配置文件
在 Spring Boot 2.3 中,配置为:
application.yml
spring:
profiles:
include:
- default
redis:
jedis:
pool:
max-active: 4
application-default.yml
spring:
profiles:
include:
- quality
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-Dev.yml
spring:
profiles:
include:
- databaseDev
myApplication:
cache:
enabled: false
我正在使用参数--spring.profiles.active=Dev 启动应用程序
在这种情况下,这里是活动配置文件The following profiles are active: default,quality,Dev,databaseDev的顺序
这是我想要的顺序。例如,键 myApplication.cache.enabled 的值为 false
我阅读了迁移到 Spring Boot 2.4 的文档,所以我现在的配置是:
application.yml
spring:
profiles:
group:
"Dev": "default, quality, databaseDev"
redis:
jedis:
pool:
max-active: 4
application-default.yml
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-Dev.yml
myApplication:
cache:
enabled: false
但现在我有活跃的个人资料The following profiles are active: Dev,default,quality,databaseDev
在这种情况下,键 myApplication.cache.enabled 的值为 true
现在配置文件 Dev 不会将 default 配置文件覆盖为 2.3,但相反 default 配置文件会覆盖 Dev 配置文件。
有没有办法将配置修改为 2.3(不使用 use-legacy-processing: true)?我是不是在某个地方弄错了?
【问题讨论】:
标签: java spring spring-boot