添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I need help for WebFlux client implementation for the latest version spring-webflux 5.1.3.RELEASE.

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

I get error The constructor ReactorClientHttpConnector((<no type> opt) -> {}) is undefined at this line ClientHttpConnector httpConnector = new ReactorClientHttpConnector(opt -> opt.sslContext(sslContext));

Do you know how I can fix this issue?

From that documentation that you linked, that constructor accepts a reactor.netty.http.client.HttpClient. The documentation for that class shows that it is not a functional interface, so you cannot use a lambda there. – Jacob G. Jan 9, 2019 at 20:55 I’ve never really worked with these frameworks, but you’ll need to pass in an HttpClient instance where you specifically set the sslContext. – Jacob G. Jan 9, 2019 at 21:00

From the doc, you need to provide a pre-defined reactor.netty.http.client.HttpClient to construct the ReactorClientHttpConnector.

For example:

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.