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
在这种情况下,有没有办法通过删除 service.api.user 两个环境中的 common 值来进一步优化它 以便其余值转到默认配置文件。
答案 0 :(得分:0)
这个建议怎么样? 如果你有 dev 和 prod 的属性,stg 和 dev 和 prod 很常见,但 stg 不常见
application.properties
service.api.user = /api/v1/user
application-dev.properties、application-prod.properties
#service.api.user = /api/v1/user
application-stg.properties
service.api.user = /api/v1/stg
如果 profile 是 dev,application-dev.properties 没有 'service.api.user' spring 找到 application.properties 的 'service.api.user'