![](/img/trans.png)
[英]In spring-boot, is it possible to get properties without being a spring bean?
[英]Spring Boot: ReactiveCrudRepository is not being implemented by any bean
我計划使用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());
}
看來您使用的是@WebMvcTest
注釋的類來測試這種情況(不過,我不確定,您的問題中缺少該部分)。
要測試Spring WebFlux應用程序,您應該使用@WebFluxTest
(請參閱參考文檔 )。 即使您這樣做,也不會出現ContributorStatRepository
bean,因為Web測試片只會考慮應用程序的Web部分,因此您通常需要使用@MockBean
對其進行模擬。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.