【问题标题】:No property findAll found for type Pairs找不到类型 Pairs 的属性 findAll
【发布时间】:2022-01-18 14:57:45
【问题描述】:

我想使用 ReactiveCrudRepository 创建一个响应式存储库

我试过这段代码:

import io.nexo.admin.console.domain.ActivePairs;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;

@Repository
public interface ActivePairsSearchRepository extends ReactiveCrudRepository<ActivePairs, Long> {
    Flux<ActivePairs> findAll(Specification spec, Pageable pageable);
}

但在部署过程中出现错误:

Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract reactor.core.publisher.Flux io.nexo.admin.console.repository.ActivePairsSearchRepository.findAll(org.springframework.data.jpa.domain.Specification,org.springframework.data.domain.Pageable)! No property findAll found for type Pairs

你知道我该如何解决这个问题吗?

【问题讨论】:

  • JPA 无法响应,因为 JPA 在设计上是阻塞的。所以这根本行不通。
  • 有哪些替代解决方案?
  • 不使用 JPA 反应式。尽管如此,它仍然是阻塞的,因此试图将其硬塞到反应堆栈中只会使事情复杂化。但是你总是可以只返回一个列表(只需使用常规的findAll 并将ListStream 转换为Flux,仍然阻塞,因为所有结果都被获取而不是以反应的方式)。跨度>
  • 你能给我看一下代码示例吗,请问如何进行转换?
  • 只需使用常规的JpaRepostiry 并在调用代码中使用Flux 工厂方法转换findAll 调用的结果。

标签: java spring spring-boot spring-data-jpa spring-webflux


【解决方案1】:

当您想通过规范查找时,您应该在方法名称中声明,例如Flux&lt;ActivePairs&gt; findBySpecification(Specification specification, Pageable pageable);

【讨论】:

    猜你喜欢
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 2020-10-16
    • 2020-09-01
    • 2019-04-08
    • 2017-12-16
    相关资源
    最近更新 更多