简体   繁体   English

错误 java.lang.ClassNotFoundException: reactor.core.scheduler.TimedScheduler

[英]Error java.lang.ClassNotFoundException: reactor.core.scheduler.TimedScheduler

While writing a test case for testing a Flux service, I am facing the following error:在编写测试 Flux 服务的测试用例时,我面临以下错误:

java.lang.ClassNotFoundException: reactor.core.scheduler.TimedScheduler

My code is like:我的代码是这样的:

FluxExchangeResult<Event> result = webTestClient.get()
.uri("/events")
.accept(MediaType.TEXT_EVENT_STREAM)
.exchange()
.expectStatus()
.isOk()
.returnResult(Event.class);

Flux<Event> eventFlux = result.getResponseBody();
StepVerifier.create(eventFlux)
.expectNextCount(10)
.expectComplete()
.verify();

I have the following dependencies in the pom:我在 pom 中有以下依赖项:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath />
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
    <groupId>org.projectreactor</groupId>
    <artifactId>reactor-spring</artifactId>
    <version>1.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>io.projectreactor</groupId>
    <artifactId>reactor-core</artifactId>
    <version>3.1.6.RELEASE</version>
</dependency>  
<dependency>
    <groupId>io.projectreactor.addons</groupId>
    <artifactId>reactor-test</artifactId>
    <version>3.0.7.RELEASE</version>
</dependency>

Have someone faced and resolved a similar issue?有没有人遇到并解决过类似的问题? I took a reference from the Dzone article: https://dzone.com/articles/spring-webflux-a-basic-crud-application-part-1我参考了 Dzone 文章: https ://dzone.com/articles/spring-webflux-a-basic-crud-application-part-1

I used a wrong dependency:我使用了错误的依赖项:

<dependency>
    <groupId>io.projectreactor.addons</groupId>
    <artifactId>reactor-test</artifactId>
    <version>3.0.7.RELEASE</version>
</dependency>

The correct one is:正确的一种是:

<dependency>
    <groupId>io.projectreactor</groupId>
    <artifactId>reactor-test</artifactId>
    <version>3.1.0.RELEASE</version>
    <scope>test</scope>
</dependency>

The one which appears as the top search for google is probably for some other use.出现在 google 顶部搜索的那个可能有其他用途。

reactor-test currently only goes up to 3.0.7.RELEASE , which includes reactor-core:3.0.7.RELEASE itself. reactor-test目前只升级到3.0.7.RELEASE ,其中包括reactor-core:3.0.7.RELEASE本身。

You will encounter classes not being found when versions do not match.当版本不匹配时,您会遇到找不到类的情况。

Therefore, you can do this因此,你可以这样做

<properties>
    <reactor.version>3.0.7.RELEASE</reactor.version>
</properties>

<dependencies>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
        <version>${reactor.version}</version>
    </dependency>  
    <dependency>
        <groupId>io.projectreactor.addons</groupId>
        <artifactId>reactor-test</artifactId>
        <version>${reactor.version}</version>
    </dependency>
</dependencies>

However, you might want to start at this documentation to get the latest compatible versions.但是,您可能希望从 本文档开始以获取最新的兼容版本。

尝试删除您的Maven(.m2)存储库并构建agin。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM