Webclient maven 依赖错误 [英] Webclient maven Dependency errors

查看:193
本文介绍了Webclient maven 依赖错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用create"创建 WebClient 实例的行中遇到 NoClassDefFoundError.尝试了 builder() 但还是一样.

I am getting a NoClassDefFoundError on the line where I try to create WebClient instance using 'create'. Tried builder() but still the same thing.

请告诉我我添加的依赖项有什么问题以及如何解决这个问题.

Please tell me what's wrong with the dependencies which I have added and how this issue can be solved.

             webClient = WebClient.create(url)
                                .post()
                                .uri(uri)
                                .contentType(MediaType.APPLICATION_JSON)
                                .body(BodyInserters.fromMultipartData(map))
                                .retrieve()
                                .bodyToMono(Object.class)
                                .block()
                                .toString()

我添加的依赖项是

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-core</artifactId>
        </dependency>

堆栈跟踪:

Exception in Async java.lang.NoClassDefFoundError: reactor/netty/http/client/HttpClient

java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: reactor/netty/http/client/HttpClient
        
        at org.springframework.http.client.reactive.ReactorClientHttpConnector.<clinit>(ReactorClientHttpConnector.java:44)
        
        at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.initExchangeFunction(DefaultWebClientBuilder.java:226)
        
        at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:207)
        
        at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:144)

Caused by: java.lang.NoClassDefFoundError: reactor/netty/http/client/HttpClient
        
        ... 16 common frames omitted

Caused by: java.lang.ClassNotFoundException: reactor.netty.http.client.HttpClient
        
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
        
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        
        ... 16 common frames omitted

推荐答案

您需要在类路径中包含 reactor-netty.默认情况下,这是 WebClient 使用的 HTTP 客户端.

You need to include reactor-netty on the classpath. As by default that is the HTTP client used by WebClient.

pom.xml:

<dependency>
    <groupId>io.projectreactor.netty</groupId>
    <artifactId>reactor-netty</artifactId>
</dependency>

更多信息:https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-client

这篇关于Webclient maven 依赖错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆