Spring boot 中的配置文件特定 application.properties 文件和多个配置文件的默认值注入

时间:2021-05-15 05:28:22

标签: java spring spring-boot configuration

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 值来进一步优化它 以便其余值转到默认配置文件。

1 个答案:

答案 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'

相关问题