java - 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值来进一步优化这一点, 以便其余值转到默认配置文件。
解决方案
这个建议怎么样?如果您具有 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
推荐阅读
- paypal - 动态自定义值贝宝按钮
- neo4j - Neo4j:仅从可能的子路径返回根节点
- android - 新活动调用 OnCreate 时崩溃
- database - 为什么在 Heroku 应用程序中我的数据库没有从 Heroku ClearDB 加载?
- java - 为什么空赋值前的引用值返回给调用方法?
- javascript - 打破 Array 循环函数的循环(map、forEach 等)
- c++ - 使用 QString 和 QByteArray 的 QDataStream 问题
- python - 将函数应用于熊猫 groupby 中的列子集
- java - 如何从父表中获取生成的 id 并插入到子表中
- javascript - 如何切片路径字符串?