应用程序 yml 属性的 Spring SpEL 表达式求值

Viv*_*thi 6 spring spring-el spring-boot

我正在尝试使用 Spring SpEL 表达式派生 application.yml 配置文件中的属性值,但看起来该表达式没有被评估。这是我的 application.yml 片段:

spring:
  profiles: local
  cloud.client.hostname: abc.pqr.xyz.lmn.westus.env.company.com
  boot:
    admin:
      client:
        instance:
            metadata.tags.environment: local
            metadata.tags.dc: "#{'${spring.cloud.client.hostname}'.split('.')[4]}"
        url: http://localhost:8079
Run Code Online (Sandbox Code Playgroud)

在运行时,该属性spring.boot.admin.client.instance.metadata.tags.dc被评估为abc.pqr.xyz.lmn.westus.env.company.com.split('.')[4],并且期望它被评估为westus

我缺少什么?

Gar*_*ell 12

不支持 SpEL application.yml

而是在代码中使用@Value("#{'${spring.cloud.client.hostname}'.split('\\.')[4]}" ) String property