当前位置: 首页 > 知识库问答 >
问题:

无法在Spring数据存储库中创建自定义查询方法[重复]

巢皓君
2023-03-14
public interface FriendRepositoryCustom {

    Page<Friend> findFriends(FriendCriteria friendCriteria, Pageable pageable);
}
@Repository
@Transactional(readOnly = true)
public class FriendRepositoryCustomImpl implements FriendRepositoryCustom {

    @PersistenceContext
    EntityManager entityManager;

    @Override
    public Page<Friend> findFriends(FriendCriteria friendCriteria, Pageable pageable) {
    ...
    }

并将其添加到主存储库:

@Repository
public interface FriendRepository extends JpaRepository<Friend, Long>, JpaSpecificationExecutor<Friend>, FriendRepositoryCustom {

}

启动应用程序时,出现以下错误:

原因:org.SpringFramework.Data.Mapping.PropertyReferenceException:未找到类型Friends的属性findFriends!在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)在$orpart.(PartTree.java:247)位于org.springframework.data.repository.query.parser.parttree$predicate.buildtree(PartTree.java:398)位于org.springframework.data.repository.query.parser.parttree$predicate.(partTree.java:378)位于org.springframework.data.repository.query.parser.parttree.86)位于org.springframework.data.jpa.repository.query.parttree.java.(partTree.java:70)...省略了43个常用框架

共有1个答案

常明亮
2023-03-14

您可能对实现类的命名有误。

请注意,命名预期在Spring Data2.0中发生了变化。

对于<2.0,必须将实现命名为最终存储库接口,并添加一个impl后缀。有关示例,请参阅匹配的参考文档。

 类似资料:
  • 错误: unsatisfiedDependencyException:创建名为“app controller”的bean时出错:通过字段“service”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatisfieddependencyexception:创建名为“jenkins service”的bean时出错:通过字段“repo”表

  • 使用Spring Boot应用程序。我有一个类UserService,我在其中创建了一个动态查询,根据请求参数具有多个or条件: 我有UserRepository接口,我需要执行这个查询。到目前为止,我使用了findById等JPA函数或@Query(“从事件中选择id”)。 如何将此查询从服务类传递到存储库并执行它?

  • 经过安装Spring屋顶的痛苦。我正在尝试创建一个项目。然而,在通过spring shell创建了pojo之后,我现在正在创建spring存储库。我运行了以下命令来创建POJO 到目前为止一切都很好,但麻烦来了: 我立刻得到这个消息——实体选项应该是一个实体。我被卡住了。我尝试删除pojo并运行以下命令: 我得到的消息是:< code >“选项‘test automatically’,‘activ

  • 基础Spring Data repository内置的查询生成器机制对于创建实体仓库的约束查询是有用的,它会从方法名中去掉find…By,read…By,query…By,count…By和get…By这些前缀并解析剩下的内容.这些前缀还能包含更多的表达式例如Distinct,设置一个distinct标志并在查询中创建它,然后第一个By的动作就像一个分隔符来表明查询实际标准的开始。最基本的方式你可

  • 问题内容: 简洁版本 我正在寻找一种将存储库类的所有findBy方法附加特定条件的方法 完整版 假设我有一个Product实体和一个Customer实体。它们都扩展了OwnerAwareEntity,并且它们都继承了ownerRef字段,该字段标识实体的所有者(它可以是商人或合作伙伴)。我想在运行时修改Product和Customer的findBy方法,以便将它们附加有ownerRef的附加条件。

  • 你好,我想用这个查询在spring创建一个自定义查询方法生成器 这是我的方法 这个查询有“(”来组合条件,所以如果可能的话。我不想写查询。谢谢。