【发布时间】:2016-07-17 13:53:24
【问题描述】:
我发现QueryDslPredicateExecutor 对减少样板文件非常有用,但它似乎是在投入活动。我现在正在尝试使用自定义基类存储库扩展 JpaRepository,并且在启动时,Spring 无法正确实例化存储库。
//Custom base class
@NoRepositoryBean
public interface IdAwareRepository<A, ID extends Serializable> extends JpaRepository<A, ID> {
// ID getId(A a);
}
// Base class implementation
public class IdAwareRepositoryImpl<A, ID extends Serializable>
extends SimpleJpaRepository<A, ID> implements IdAwareRepository<A, ID> {
public IdAwareRepositoryImpl(JpaEntityInformation<A, ?> entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
}
}
// Individual repo
@Repository
public interface MyPojoRepository extends JpaRepository<MyPojo, Integer>, QueryDslPredicateExecutor<MyPojo> {
}
// 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) 在 org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) 在 org.springframework.data.repository.query.parser.Part.(Part.java:76) 在 org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:235) 在 org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) 在 org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:353) 在 org.springframework.data.repository.query.parser.PartTree.(PartTree.java:84) 在 org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:62) 在 org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:100) 在 org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211) 在 org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:74) 在 org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:416) 在 org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(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(JpaRepositoryFactoryBean.java:92) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
对我来说,Spring 无法将自定义基类和 QueryDslPredicateExecutor 扩展连接到 JpaRepository
【问题讨论】:
-
我遇到了完全相同的问题。你找到解决办法了吗?
-
不,还没有。我一直打算制作一个重现错误的小项目,以便为 Spring 或 Spring Data 开发人员提供可重现的错误。
-
感谢您的回复!
标签: java spring spring-boot spring-data-jpa querydsl