这就是我的 .yaml
属性文件中的一行的样子:
profiles.active: rabbit-${CLUSTER_ENV}, mongo-${CLUSTER_ENV} ...
我只想将以下逻辑仅用于 rabbit-
属性:
if(CLUSTER_ENV == "local") {
return "dev";
} else {
return CLUSTER_ENV;
}
其他属性应该用local
填充,但只有在这个地方,属性值才应该有条件地填充。我可以以某种方式在 Spring yaml 属性中添加此逻辑吗?
最佳答案
它看起来不太漂亮,但你可以使用类似的东西:
#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}}
问候, 威普
根据评论更新:
#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}}
关于java - Spring条件yaml属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56321412/