首页 > 解决方案 > 是否可以在 spring-boot application.yaml 或 properties 中使用占位符 ${} 作为属性 KEY

问题描述

我想知道是否可以不仅在值中使用占位符替换,还可以在弹簧引导application.yaml(或.properties)中使用占位符替换。

例如:

  openapi:
    security:
      - my-resource
        - ${some.path.role-a}
        - ${some.path.role-b}

工作就像一种魅力,这里没什么特别的。但是,如果我还需要从“占位符”中获取“我的资源”怎么办?那可能吗?

已经尝试过不同的方法,例如:

  openapi:
    security:
      - ${some.path.resource}
        - ${some.path.role-a}
        - ${some.path.role-b}

或者

  openapi:
    security:
      - "${some.path.resource}"
        - ${some.path.role-a}
        - ${some.path.role-b}

但是一切都只产生变量名作为键。

标签: springspring-bootproperty-placeholder

解决方案


推荐阅读