我计划使用 Cassandra 来响应式保存数据。为此,我编写了以下接口(interface):
@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 吗?
我正在使用 Spring boot 2.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());
}
最佳答案
您似乎正在使用 @WebMvcTest
带注释的类来测试此案例(但我不确定,您的问题中缺少该部分)。
要测试 Spring WebFlux 应用程序,您应该使用 @WebFluxTest
(请参阅 reference documentation )。即使您这样做,ContributorStatRepository
bean 也不会出现,因为 Web 测试切片只会考虑应用程序的 Web 部分,并且您通常需要使用 @MockBean
来模拟这一部分。
关于java - Spring 启动: ReactiveCrudRepository is not being implemented by any bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47820325/