0

I'm trying to use Spring Cloud OpenFeign (v4.0.2) to create a @FeignClient that uses an url set by a property given in runtime or through Spring Cloud Config.

@FeignClient(name = "my-client")
public interface MyClient {
    @GetMapping("/getCustomers")
    List<String> getCustomers();
}

I want to set the url in an application.yaml file:

spring:
  cloud:
    openfeign:
      client:
        config:
          my-client:
            url: http://client-service/
    refresh:
      enabled: false

I've followed the documentation about AOT/Native support, but I get the following error while running a native image:

java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

I don't want to use Spring Cloud LoadBalancer, but in the given documentation it says:

However, if you set the url value via properties, it is possible to override the @FeignClient url value by running the image with -Dspring.cloud.openfeign.client.config.[clientId].url=[url] flag. In order to enable overriding, a url value also has to be set via properties and not @FeignClient attribute during buildtime.

On the other hand, in this github issue, @OlgaMaciaszek says that:

It is by design. If an empty url has been provided, we try resolving the instance with the LB.

So, is it possible to use OpenFeign in native mode with property-based urls without using LoadBalancers? The documentation is not clear about this:

  • If I build the native image with @FeignClient(url = "${spring.cloud.openfeign.client.config.my-client.url}") I won't be able to override it during runtime
  • If I build the native image with @FeignClient() AOT tries to resolve it with LoadBalancers.
  • I was able to get it working by passing the parameters as arguments to the executable, i.e. by passing `-Dspring.cloud.openfeign.client.config.my-client.url=http://client-service/`. – Diego Pedraza Aug 28 '23 at 06:46

0 Answers0