为了账号安全,请及时绑定邮箱和手机立即绑定

Spring 条件 yaml 属性值

Spring 条件 yaml 属性值

Qyouu 2022-12-15 17:09:51
.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}


查看完整回答
反对 回复 2022-12-15
  • 1 回答
  • 0 关注
  • 79 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信