首页 > 解决方案 > 接口中定义的 Spring WebClient 端点

问题描述

我问了一个问题,如何用 Spring 替代品替换 JAXrs 客户端,但没有得到回答,但我想我现在知道用 WHAT 替换 jax 的答案,但不知道如何替换。

我决定使用 Spring 的 WebClient,因为 RestTemplate 处于维护模式,将来会被弃用。

现在知道我应该使用 WebClient - 我还有另一个问题。

如果我有一个带有注释的 Rest Endpoints 的接口,我如何将此接口与 WebClient 一起使用?或者我应该只是简单地在每个方法中分别使用 url 和 http 方法创建请求?

我有这个界面

@RequestMapping("/theResource")
public interface TheResource {

    @GetMapping( value = "/test")
    ResponseEntity<String> test();

我想知道是否有办法在 WebClient 中使用这些信息?

我知道我能做到

WebClient.RequestBodySpec uri = client
  .method(HttpMethod.GET)
  .uri("/theResource/test");

但是有没有办法只用上面提到的接口创建 WebClient 呢?

我在这里问了原始问题 Spring Alternative to JAXRSClientFactory

标签: javaspringspring-mvcspring-webflux

解决方案


推荐阅读