How to bind a Feign Client url from the YAML when the url is located at a index of a List

Viewed 486

Hello new to Java and Springboot. I currently have my integrations set up in this way. It needs to stay as a List so I could add the clients in one place instead of two.

application.yaml

lr:
  main-product-client.url: http://localhost:8081
  product-client-properties:
    - type: productone
      use-proxy: false
      url: someUrl
    - type: producttwo
      use-proxy: true
      url: someUrl
    - type: productthree
      use-proxy: true
      url: someUrl

ProductOneClient.java

@FeignClient(
    value = "productOneClient",
    url = "${lr.product-client-properties(0).url}",
    configuration = ProductOneClient.ProductOneClientConfig.class)
public interface ProductOneClient {
...

This fails to read the placeholder for ${lr.product-client-properties(0).url}. What's the proper way to retrieve the integration url for my ProductOne client? Thank you for your time!

1 Answers

Can you change your yaml file to be like this?:

lr:
  main-product-client.url: http://localhost:8081
  product-client-properties:
    client-one:
      type: productone
      use-proxy: false
      url: someUrl
    client-two:
      type: producttwo
      use-proxy: true
      url: someUrl
    client-three:
      type: productthree
      use-proxy: true
      url: someUrl

and use in @Value like this:

@Value( "${lr.product-client-properties.client-one.url}")
Related