Spring SpEL expression evaluation for an application yml property

Viewed 4121

I am trying to derive a value for a property in my application.yml config file using Spring SpEL expression, but it looks like the the expression is not getting evaluated. Here's my application.yml snippet:

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

During runtime, the property spring.boot.admin.client.instance.metadata.tags.dc is being evaluated to abc.pqr.xyz.lmn.westus.env.company.com.split('.')[4] and expectation is that it be evaluated to westus.

What am I missing?

1 Answers

SpEL is not supported in application.yml.

Use @Value("#{'${spring.cloud.client.hostname}'.split('\\.')[4]}" ) String property in code instead.

Related