spring-bootspring-cloudspring-cloud-feignopenfeignproperty-placeholder

Reading FeignClient url from application.yaml not working


I am trying to read the Feign client url from application.yaml, I am not using ribbon. Ribbon worked before now I migrated to spring boot 3.1.4 and spring cloud 2022.0.3

@FeignClient(name = "new-common-service", url = "${spring.cloud.openfeign.client.config.new-common-service.url}")
public interface NewCommonServiceClient {
@GetMapping(value = "/test")
ResponseEntity<?> testRequest();

}

In application yaml

cloud:
    openfeign:
      client:
        config:
          new-common-service:
          url: localhost:9090/serve

It is showing error

java.lang.IllegalArgumentException: http://${cloud.openfeign.client.config.new-common-service.url} is malformed Caused by: java.net.MalformedURLException: Illegal character found in host: '{'

how to fix this issue

I expect FeignClient url value to be read from the application yaml file


Solution

  • For anyone having this issue, this solved it for me:

    spring.cloud.openfeign.lazy-attributes-resolution=true
    

    Source: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/#attribute-resolution-mode