问题描述
我想创建自定义存储库:
I wanted to create custom repository :
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) {
...
}
并将其添加到主存储库:
And added it to main repository :
@Repository
public interface FriendRepository extends JpaRepository<Friend, Long>, JpaSpecificationExecutor<Friend>, FriendRepositoryCustom {
}
启动应用程序时出现此错误:
When i start application i get this error :
推荐答案
您可能将自己的实现类命名为错误.
You are probably naming your implementation class wrong.
请注意,命名期望随着Spring Data 2.0的改变而改变.
Note that the naming expectations changed with Spring Data 2.0.
对于< 2.0必须将实现命名为带有附加Impl
后缀的最终存储库接口. 请参阅匹配参考文档的示例.
For < 2.0 the implementation had to be named as the final repository interface with an additional Impl
suffix. See the matching reference documentation for an example.
对于> = 2.0,必须将实现命名为带有附加Impl
后缀的自定义接口. 请参阅当前参考文档中的示例.
For >= 2.0 the implementation has to be named as the custom interface with an additional Impl
suffix. See the current reference documentation for an example.
注意:您不需要任何@Repository
批注.
Note: You don't need any of the @Repository
annotations.
这篇关于无法在Spring Data Repository中创建自定义查询方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!