.yaml这就是我的属性文件的一行:profiles.active: rabbit-${CLUSTER_ENV}, mongo-${CLUSTER_ENV} ...我只想为rabbit-属性添加以下逻辑:if(CLUSTER_ENV == "local") { return "dev";} else { return CLUSTER_ENV;}应该填充其他属性,local但只有在这个地方应该有条件地填充属性值。我可以以某种方式在 Spring yaml 属性中添加这个逻辑吗?
1 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
它看起来不漂亮,但你可以使用类似的东西:
#this can be added on startup
mykey: key1
#a map with your condition
mymap:
key1: val1
key2: val2
#your value based on the condition
conditional: con-${mymap.${mykey}}
问候, WiPU
根据评论更新:
#this can be added on startup as variable
mykey: local
#a map with your condition
mymap:
local: dev
xyz: test
# your value based on the condition or the key as fallback if the key is not
# present in mymap.
conditional: con-${mymap.${mykey}:${mykey}
添加回答
举报
0/150
提交
取消