How can I change the feign URL during the runtime?

You can add an unannotated URI parameter (that can potentially be determined at runtime) and that will be the base path that will be used for the request. E.g.:

    @FeignClient(name = "dummy-name", url = "https://this-is-a-placeholder.com")
    public interface MyClient {
        @PostMapping(path = "/create")
        UserDto createUser(URI baseUrl, @RequestBody UserDto userDto);
    }

And then the usage will be:

    @Autowired 
    private MyClient myClient;
    ...
    URI determinedBasePathUri = URI.create("https://my-determined-host.com");
    myClient.createUser(determinedBasePathUri, userDto);

This will send a POST request to https://my-determined-host.com/create (source).

Leave a Comment