java-自定义存储库基类QueryDslPredicateExecutor
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-自定义存储库基类QueryDslPredicateExecutor,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4125字,纯文字阅读大概需要6分钟。
内容图文
![java-自定义存储库基类QueryDslPredicateExecutor](/upload/InfoBanner/zyjiaocheng/690/a085ad9afc8d400c96ac17eb6260ac05.jpg)
我发现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上遇到了类似的问题,但没有对此修复程序进行任何解释,只是重构了代码以使其更易于使用.
我收到以下错误:
Caused by:
org.springframework.data.mapping.PropertyReferenceException: No
property findAll found for type MyPojo! at
org.springframework.data.mapping.PropertyPath.(PropertyPath.java:77)
at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
at
org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
at
org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
at
org.springframework.data.repository.query.parser.Part.(Part.java:76)
at
org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:235)
at
org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373)
at
org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:353)
at
org.springframework.data.repository.query.parser.PartTree.(PartTree.java:84)
at
org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:62)
at
org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:100)
at
org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211)
at
org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:74)
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:416)
at
org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206)
at
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
at
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
at
org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
对我来说,Spring无法将自定义基类和QueryDslPredicateExecutor扩展都连接到JpaRepository
解决方法:
我通过使基础存储库扩展QueryDslMongoRepository解决了类似的问题.
您也许能够扩展类似的课程.
内容总结
以上是互联网集市为您收集整理的java-自定义存储库基类QueryDslPredicateExecutor全部内容,希望文章能够帮你解决java-自定义存储库基类QueryDslPredicateExecutor所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。