【发布时间】:2020-11-04 06:43:17
【问题描述】:
我使用 Spring Boot 和 Webflux。
在我的代码中,我尝试返回 Flux,但我从 intellij 收到以下错误并且代码标记为红色:
no instance(s) of type variable(s) R exists so that Flux<UUID> conforms to Mono<>
我的代码:
public Flux<UUID> deleteCCProtections(Mono<ProtectionSetRequest> protectionSetRequest) {
return protectionSetRequest.flatMap(
request ->
protectionSetRepository
.findByProtectionSetIdIn(request.getProtectionSetIds())
.collectList()
.flatMap(
protectionSet -> //this line is marked red in Intellij
deleteCCProtectionset(protectionSet, request.getDeleteBackups()))); //this line is marked red in Intellij
}
private Flux<UUID> deleteCCProtectionset(
List<ProtectionSet> protectionSets, boolean deleteRecoveryPoints) {
return Flux.fromIterable(protectionSets)
.flatMap(
protectionSet ->
protectorRepository
.findByProtectionId(protectionSet.getProtectionId())
.flatMap(
protector ->
Mono.zip(
protectBatchService.delete(protector),
protectionSetRepository.delete(protectionSet))
.flatMap(
tuple ->
protectionService.sendUnprotectCommand(
tuple.getT1()))
.doOnNext(subscriptionResourceService::cancelSubscriptionResources)
//
// .doOnNext(agentDataServiceApi::setProtectedResources) //void
.doOnNext(schedulerService::deleteProtection))); //void
}
我做错了什么?
更新
当我从参数 deleteCCProtections(Mono protectionSetRequest 中删除 Mono 时,我的代码会编译 - 为什么???我将 Mono 从控制器获取到服务...
工作代码但没有 Mono
public Flux<UUID> deleteCCProtections(ProtectionSetRequest protectionSetRequest) {
return protectionSetRepository
.findByProtectionSetIdIn(protectionSetRequest.getProtectionSetIds())
.collectList()
.flatMapMany(
protectionSet -> //this line is marked red in Intellij
deleteCCProtectionset(protectionSet, request.getDeleteBackups()))); //this line is marked red in Intellij
}
private Flux<UUID> deleteCCProtectionset(
List<ProtectionSet> protectionSets, boolean deleteRecoveryPoints) {
return Flux.fromIterable(protectionSets)
.flatMap(
protectionSet ->
protectorRepository
.findByProtectionId(protectionSet.getProtectionId())
.flatMap(
protector ->
Mono.zip(
protectBatchService.delete(protector),
protectionSetRepository.delete(protectionSet))
.flatMap(
tuple ->
protectionService.sendUnprotectCommand(
tuple.getT1()))
.doOnNext(subscriptionResourceService::cancelSubscriptionResources)
//
// .doOnNext(agentDataServiceApi::setProtectedResources) //void
.doOnNext(schedulerService::deleteProtection))); //void
}
【问题讨论】:
标签: java spring-boot spring-webflux