HTTP Micronaut声明式客户端是否可以更改服务器?

5
我是一个翻译引擎,可以翻译文本但不能解释其含义。
我正在使用Micronaut的声明式HTTP客户端从API中检索数据。但现在我需要在运行时动态更改服务器地址。这可能吗?
示例:
@Client("${http.client.url}")
@Header(name="Accept-Encoding", value="gzip, deflate, br")
public interface CatalogClientApi {

有没有办法改变"${http.client.url}"?还是我必须切换到低级别的http客户端?

3个回答

4

@Client注解可以注入RxHttpClient。

你可以使用声明性方法来实现。

URL url = new URL("http://your-url-here.com");
RxHttpClient client = RxHttpClient.create(url);


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

"@Client"有一个占位符,然后服务器将在{+path}中使用路径变量。我发现在这里使用主机有点误导,但它完美地工作。

-1

你必须切换。Micronaut中的注解在编译时处理。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接