首页 > 解决方案 > Spring boot 中配置文件特定的 application.properties 文件和多个配置文件的默认值注入

问题描述

应用程序属性:

app.profile=${spring.profiles.active} spring.profiles.active=dev

service.endpoint=${${spring.profiles.active}.service.endpoint} service.api.user=${${spring.profiles.active}.service.api.user}

开发者

dev.service.endpoint = https://test.google.com/dev.service.api.user
= /api/v1/user

产品

prod.service.endpoint = https://google.com/prod.service.api.user
= /api/v1/user

有没有办法通过删除两个环境中的 common which 在这种情况下的service.api.user值来进一步优化这一点, 以便其余值转到默认配置文件。

标签: javaspringspring-bootconfiguration

解决方案


这个建议怎么样?如果您具有 dev 和 prod 的属性,则 stg 并具有 dev 和 prod 是常见的,但 stg 并不常见

应用程序属性

service.api.user = /api/v1/user

应用程序-dev.properties,应用程序-prod.properties

#service.api.user = /api/v1/user

应用程序-stg.properties

service.api.user = /api/v1/stg

如果配置文件是 dev 时,application-dev.properties 没有 'service.api.user' spring find 'service.api.user' of application.properties


推荐阅读