有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring引导:任何bean都没有实现ReactiveCrudepository

我计划使用Cassandra以反应方式保存数据。为此,我编写了以下界面:

@Repository
public interface ContributorStatRepository extends ReactiveCrudRepository<ContributorStat, Long> {
    Flux<ContributorStat> findByAkonId(String akonId);
}

将引发上述异常:

com.example.sample.controller.ContributorStatControllerTest > shouldReturnBadRequestWithBlankContributorStat FAILED
    java.lang.IllegalStateException
        Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException
            Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException
                Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

您知道为什么没有为ContributorStatRepository创建合适的bean吗

我使用的是SpringBoot2.0.0。M7和这些依赖项:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('javax.xml.bind:jaxb-api:2.3.0')
    compile('org.springframework.boot:spring-boot-starter-webflux')
    compile('org.springframework.boot:spring-boot-starter-data-cassandra-reactive')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('io.projectreactor:reactor-test')
}

已更新: 运行测试:

@Test
public void shouldReturnBadRequestWithBlankContributorStat() throws Exception {
    requestPayload = mapper.writeValueAsString(new ContributorStatDTO());

    this.mockMvc.perform(post(CONTRIBUTOR_STATS_ROUTE)
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .content(requestPayload)).andDo(print())
            .andExpect(status().isBadRequest());
}

共 (1) 个答案

  1. # 1 楼答案

    似乎您正在使用@WebMvcTest注释类来测试这个案例(但我不确定,您的问题中缺少这一部分)

    要测试Spring WebFlux应用程序,应该使用@WebFluxTest(请参见reference documentation)。即使是这样,^ {< CD3}} bean也不会存在,因为Web测试切片只考虑应用程序的Web部件,通常需要用^ {CD4}}来模拟这一个。