自定义存储库基类+ QueryDslPredicateExecutor

我发现QueryDslPredicateExecutor对于减少样板非常有用,但它似乎正在投入一个猴子扳手。 我现在正在尝试使用自定义基类存储库扩展JpaRepository ,并且在启动时,Spring无法正确实例化存储库。

 //Custom base class @NoRepositoryBean public interface IdAwareRepository extends JpaRepository { // ID getId(A a); } // Base class implementation public class IdAwareRepositoryImpl extends SimpleJpaRepository implements IdAwareRepository { public IdAwareRepositoryImpl(JpaEntityInformation entityInformation, EntityManager entityManager) { super(entityInformation, entityManager); } } // Individual repo @Repository public interface MyPojoRepository extends JpaRepository, QueryDslPredicateExecutor { } // Spring boot main application class @EnableJpaRepositories(repositoryBaseClass = IdAwareRepositoryImpl.class) @EntityScan(basePackageClasses = {Application.class, Jsr310JpaConverters.class}) @EnableAutoConfiguration(exclude = { org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class, org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration.class}) @SpringBootApplication public class Application {} 

我已经尝试了几个关于这个主题的变体,但是没有幸运地成功连线。 我在Spring的问题跟踪器https://jira.spring.io/browse/DATAJPA-674上遇到了类似的问题,但没有解释修复,只是代码被重构为更容易使用。

我收到以下错误:

引起:org.springframework.data.mapping.PropertyReferenceException:找不到类型MyPojo的属性findAll! org.springframework.data.mapping.PropertyPath。(PropertyPath.java:77)org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)org.springframework.data.mapping.PropertyPath.create( PropertyPath.java:309)org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)atg.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)org.springframework.data位于org.springframework.data.repository.query的org.springframework.data.repository.query.parser.PartTree $ OrPart。(PartTree.java:235)的.repository.query.parser.Part。(Part.java:76)。 .parser.PartTree $ Predicate.buildTree(PartTree.java:373)位于org.springframework.data.repository.query的org.springframework.data.repository.query.parser.PartTree $ Predicate。(PartTree.java:353)。解析器.PartTree。(PartTree.java:84)org.springframework.data.jpa.repository.query.PartTreeJpaQuery。(PartTreeJpaQuery.java:62)org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy $ CreateQueryLookupStr ategy.resolveQuery(JpaQueryLookupStrategy.java:100)位于org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy $ CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211)org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy $位于org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor。(RepositoryFactorySupport.java:416)的orQuery.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository上的AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:74) (RepositoryFactorySupport.java:206)org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java) :237)org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaReposito) ryFactoryBean.java:92)atg.springframework.bens.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

对我来说,Spring无法将自定义基类和QueryDslPredicateExecutor扩展连接到JpaRepository

我通过让我的基础存储库扩展QueryDslMongoRepository来解决类似的问题。
您可能能够扩展类似的课程。

“找不到类型的属性”……将QueryDslPredicateExecutor与MongoDB和Spring-Data一起使用时