R2dbcRepository BeanCreationException没有属性findAll找到类型

问题描述

我尝试更新整个应用程序并在Postgresql中使用反应式编程方法,因此我正在更新存储库,并使它们从R2dbcRepository扩展,还更新了相关的服务以处理Mono和Flux。 当我尝试运行该应用程序时,我遇到了异常

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'temperatureLibraryReactiveRepository'
defined in com.PlayGroundAdv.solar.repositories.reactive.TemperatureLibraryReactiveRepository defined
in @EnableR2dbcRepositories declared on Solarapplication: Invocation of init method Failed
nested exception is java.lang.IllegalArgumentException: Failed to create query for method 
public abstract reactor.core.publisher.Flux
com.PlayGroundAdv.solar.repositories.reactive.TemperatureLibraryReactiveRepository.findAll(org.springframework.data.domain.Pageable)! 
No property findAll found for type TemperatureLibraryEntity!

我不确定这是否是由于使用Pageable而引起的,如果是这种情况,我没有找到使用R2DBC方法替代Pageable的任何方法

过去使用JPA方法都能正常工作 这是我的资料库

import com.PlayGroundAdv.solar.entity.TemperatureLibraryEntity;
import com.PlayGroundAdv.solar.model.AllPostalcodemodel;
import org.springframework.data.domain.Pageable;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;

import javax.transaction.Transactional;

@Repository
public interface TemperatureLibraryReactiveRepository extends R2dbcRepository<TemperatureLibraryEntity,Long> {

    // A.B 11-18 Get All Temp By postal Code
    Flux<TemperatureLibraryEntity> findByPostalCode(String postalCode,Pageable pageable);

    String FIND_POSTAL_CODE = "SELECT new com.PlayGroundAdv.solar.model.AllPostalcodemodel ( u.id,u.postalCode) FROM TemperatureLibraryEntity u order by u.postalCode";

    @Transactional
    @Modifying
    @Query(value = FIND_POSTAL_CODE)
    Flux<AllPostalcodemodel> findAllPostalCode();
    Flux<TemperatureLibraryEntity> findAll(Pageable pageable);
}

解决方法

  1. 删除@repository批注,将basePackages设置为包含EnableR2dbcRepositories中存储库的软件包。

  2. 对于分页,请检查this post。现在没有PaginationAndSortRepository用于反应性情况。

检查来自my reactive sample repository的有关R2dbc的示例。

还有the sample for the lastest Spring 5.3 and Spring Data R2dbc 1.2,有an example for pagination。此版本中引入了一些重大更改,下周发布具有里程碑错误的下一个里程碑(Spring Data R2dbc 1.2.0-RC1)时,我将更新示例代码。