当前位置: 首页 > 知识库问答 >
问题:

Webflux错误-不存在类型变量R的实例,因此flux符合mono

颜宸
2023-03-14

我使用Spring Boot和WebFlux。

在我的代码中,我试图返回一个流量,但从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时(Mono protectionSetRequest是我的代码编译的-为什么???我从控制器到服务将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
    }

共有1个答案

闻人嘉木
2023-03-14

由于deleteccprotectionset返回flux ,因此在deleteccprotections方法中应该使用flatmapmany而不是flatmap

public Flux<UUID> deleteCCProtections(Mono<ProtectionSetRequest> protectionSetRequest) {
    return protectionSetRequest.flatMapMany(request -> protectionSetRepository
            .findByProtectionSetIdIn(request.getProtectionSetIds())
            .collectList()
            .flatMapMany(protectionSet -> deleteCCProtectionset(protectionSet, request.getDeleteBackups())));
}
 类似资料: