ReactorClientHttpConnector((<no type =“”> opt)-> {})未定义

时间:2019-01-09 20:41:53

标签: java spring spring-boot netty spring-webflow

对于最新版本的spring-webflux 5.1.3.RELEASE,我需要WebFlux客户端实现的帮助。

public RestClient(String gatewayUrl, String token, String username, String password, SslContext sslContext) {
        this.token = token;
        WebClient.Builder builder = WebClient.builder().baseUrl(gatewayUrl);
        if (sslContext != null) {
            ClientHttpConnector httpConnector = new ReactorClientHttpConnector(opt -> opt.sslContext(sslContext));
            builder.clientConnector(httpConnector);
        }
        if (username != null && password != null) {
            builder.filter(basicAuthentication(username, password));
        }
        client = builder.build();
    }

    public Mono<Response> execute(Transaction transaction) {
        Mono<Transaction> transactionMono = Mono.just(transaction);
        return client.post().uri("/v1/{token}", token)
                .header(HttpHeaders.USER_AGENT, "client")
                .accept(MediaType.APPLICATION_XML)
                .contentType(MediaType.APPLICATION_XML)
                .body(transactionMono, Transaction.class)
                .retrieve()
                .bodyToMono(Response.class);
    }

此行The constructor ReactorClientHttpConnector((<no type> opt) -> {}) is undefined出现错误ClientHttpConnector httpConnector = new ReactorClientHttpConnector(opt -> opt.sslContext(sslContext));

您知道如何解决此问题吗?

1 个答案:

答案 0 :(得分:1)

doc,您需要提供一个预定义的reactor.netty.http.client.HttpClient来构建ReactorClientHttpConnector

例如:

HttpClient httpClient = HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
ClientHttpConnector httpConnector = new ReactorClientHttpConnector(httpClient);