可以在 HTTP micronaut 声明性客户端中更改服务器吗?

mab*_*org 5 micronaut

我正在使用 Micronaut 的声明式 http 客户端从 API 检索数据。但现在我需要在运行时动态更改服务器地址。这是可能的 ?

例子:

@Client("${http.client.url}")
@Header(name="Accept-Encoding", value="gzip, deflate, br")
public interface CatalogClientApi {
Run Code Online (Sandbox Code Playgroud)

可以以某种方式更改“${http.client.url}”吗?或者我必须切换到低级http客户端?

mab*_*org 4

然后我找到了一个简单的解决方案(有点难看):

@Client("/")
@Header(name="Accept-Encoding", value="gzip, deflate, br")
public interface ExampleApi {
    @Post("{+path}/V1/products")
String post(@PathVariable String path, @Header("Authorization") String token, Body product);
Run Code Online (Sandbox Code Playgroud)

“@Client”有一个 / 占位符,然后服务器将位于 {+path} 中使用的路径变量中。我发现这里使用主机有点误导,但它工作得很好。