Search code examples
spring-bootspring-cloudspring-cloud-gateway

How to inject a variable placeholder `${}` in the spring gateway filters configuration?


How to inject a variable placeholder ${} in the spring gateway filters configuration?

foo:
  bar: 
    uri: /coucou

spring:
  cloud:
    gateway:
      routes:
      - id: prefixpath_route
        uri: https://example.org
        filters:
        - PrefixPath=$\\{foo.bar.uri}

NB:

  • I've tried $\{foo.bar.uri} and ${foo.bar.uri}
  • I know it's doable programmatically

Solution

  • As @spencergibb highlighted, it's working by using args subproperty:

       filters:
        - name: PrefixPath
          args:
            prefix: ${foo.bar.uri}
    

    see gist.github.com/spencergibb/873f239529f79cb784d4eab3a9ddc4a6