0

我尝试更新整个应用程序并使用 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,如果是这种情况,我没有找到PageableR2DBC 方法的任何替代方法。

过去使用 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);
}
4

1 回答 1

0
  1. 删除@repository注释,设置basePackages为包含EnableR2dbcRepositories.

  2. 对于分页,请查看这篇文章。现在没有PaginationAndSortRepository反应式案例。

从我的响应式示例存储库中检查有关 R2dbc 的示例。

最新的 Spring 5.3和Spring Data R2dbc 1.2的示例,有一个分页示例。此版本中引入了一些重大更改,我将在下周发布下一个里程碑(Spring Data R2dbc 1.2.0-RC1)时更新示例代码,其中包括一些错误修复。

于 2020-09-12T02:50:38.517 回答