【发布时间】:2018-05-28 22:54:25
【问题描述】:
我计划使用 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吗?
我正在使用 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());
}
【问题讨论】:
-
您能提供更多信息吗?您的存储库接口看起来很奇怪(声明了两倍的扩展接口?)并且您没有显示您正在运行的测试类。另外,为什么要在组合中添加 spring-data-jpa?
-
@BrianClozel 哦,我忘了删除注释行。刚刚更新了。感谢您的观察。包含 spring-data-jpa 以创建另一个非反应性存储库。我包含了测试,但实际上所有测试都失败了,因为没有找到该存储库的 bean。
-
@Jovanny 你有没有在任何地方添加
@Enable*Repositories?例如。喜欢this example? -
@Brian,是的,我有一个标记为
@Configuration和@EnableReactiveCassandraRepositories的配置类
标签: java spring-boot spring-data spring-data-cassandra spring-webflux