如何在运行时更改伪装 URL? [英] How can I change the feign URL during the runtime?

查看:54
本文介绍了如何在运行时更改伪装 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@FeignClient(name = "test", url="http://xxxx")

如何在运行时更改 feign URL (url="http://xxxx")?因为 URL 只能在运行时确定.

How can I change the feign URL (url="http://xxxx") during the runtime? because the URL can only be determined at run time.

推荐答案

您可以添加未注释的 URI 参数(可能在运行时确定),这将是用于请求的基本路径.例如:

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);
}

然后用法是:

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

这将向 https://my-determined-host.com/create (source).

这篇关于如何在运行时更改伪装 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆