Spring Data JPA中自定义存储库实现中的分页

时间:2017-08-28 09:10:14

标签: spring spring-data-jpa

我不想在服务层中获取Page对象,理想情况下,服务层应该与DAO层分离,而JPA特定代码不应该存在于服务层中。

因此,我尝试在自定义存储库层中移动以下语句:  Page recordsPage = recordRepository.findAll(pageRequest);

我通过实现一个实现自定义存储库接口的自定义存储库类来实现这一点,而我的实际存储库类扩展了PagingAndSortingRepository,RecordRepositoryCustom。

但问题是,我无法在RepoImpl类中自动装载RecordRepository。我需要RecordRepository的引用来调用JPA方法。 我收到以下错误:

org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名为'recordRepositoryImpl'的bean时出错:请求的bean当前正在创建:是否存在无法解析的循环引用?

我做了研究并确定了命名约定,以下链接也给出了同样的例外:

CrudRepository inside my custom repository implementation

我也在Spring社区中遵循相同的主题,但没有针对该问题的解决方案: http://forum.spring.io/forum/spring-projects/data/123225-spring-data-calling-default-crud-methods-inside-a-custom-repository-implementation

以下线程给出一个解决方案是在ChildRepositoryImpl类中实现接口ApplicationContextAware并像applicationContext.getBean()一样读取bean。还有其他简单的approch来解决它吗?

How to use my base repository methods in custom implementation repository in Spring-Data-JPA?

0 个答案:

没有答案