Spring Boot 如何在maven中使用特定版本的依赖项?

5us2dqdw  于 2023-03-02  发布在  Spring
关注(0)|答案(2)|浏览(141)

我在springboot 3中有一个项目,我想使用一些来自互联网的服务,我实现了一个webclient,这里是我的webclient定义

@Bean
    public WebClient createWebClient(@Value("${internet.service.url}") String urlInternet) {
        return WebClient.builder().baseUrl(urlInternet)
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .build();
    }

这是我的祈祷

public InternetCreateResponse walletCreate(InternetCreateRequest request) {
    Mono<InternetCreateResponse> response =  webClient.post().uri("create_account")
            .body(Mono.just(request), InternetCreateRequest.class)
            .retrieve()
            .onStatus(
                    (HttpStatusCode::is4xxClientError),
                    error -> Mono.error(new RuntimeException("something was wrong")))
            .onStatus(HttpStatusCode::is5xxServerError,
                    error -> Mono.error(new RuntimeException("Server is down")))
            .bodyToMono(InternetCreateResponse.class);
    return response.block();
}

但是当我执行response.block()时,我遇到了一个错误,这里是stacktrace

Exception in thread "grpc-default-executor-0" java.lang.NoSuchMethodError: 'reactor.util.context.ContextView reactor.core.publisher.MonoSink.contextView()'
at reactor.netty.http.client.HttpClientConnect$HttpObserver.<init>(HttpClientConnect.java:329)
at reactor.netty.http.client.HttpClientConnect$MonoHttpConnect.lambda$subscribe$0(HttpClientConnect.java:259)
at reactor.core.publisher.MonoCreate.subscribe(MonoCreate.java:57)
at reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:77)
at reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57)
at reactor.netty.http.client.HttpClientConnect$MonoHttpConnect.subscribe(HttpClientConnect.java:272)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:55)
at reactor.core.publisher.Mono.subscribe(Mono.java:4361)
at reactor.core.publisher.Mono.block(Mono.java:1705)
at io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.onHalfClose(ServerCalls.java:182)
at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35)
at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23)
at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40)
at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35)
at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23)
at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40)
at io.grpc.Contexts$ContextualizedServerCallListener.onHalfClose(Contexts.java:86)
at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:340)
at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed.runInContext(ServerImpl.java:866)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)

在这里Springwebflux和reactor

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

但我不知道我的React堆核心版本是3.4.10

stacktrace中的消息很清楚,但不幸的是我不能告诉maven我想排除那个版本,我看到一些像thisthisthisthis的链接,但它没有像我预期的那样工作。我想使用reactor-core版本3.5.3,它包含reactor.core.publisher.MonoSink.contextView()方法。
你知道我该怎么做吗?
或者我可以用别的方法?

ekqde3dh

ekqde3dh1#

如果你想知道3.4.10是从哪里来的,使用mvn dependency:tree,它将输出依赖关系图。使用它,你可以确定哪个jar传递性地提供reactor-core。一旦你找到了jar,只需添加reactor-core作为排除项。
但是,我应该警告您,除非您有非常好的理由覆盖Spring提供的版本,否则我不会更改它。

rqcrx0a6

rqcrx0a62#

堆芯的这种相关性是Spring Boot腹板通量的相关性。
通过手动添加依赖项,可以覆盖与启动器依赖项捆绑在一起的依赖项,它们可能不兼容。
如果你从你的pom中删除了React堆堆芯的依赖性,然后进行一个干净的安装,同样的错误会发生吗?

相关问题