[英]Calling custom mongoDB query with spring data fails
我正在尝试使用spring数据调用自定义mongoDB查询,但查询未得到调用。
这是我的代码。
在Controller中:调用服务方法
List<UserProfile> gatheringMembers = userService.getUsersProfile(membersEmail);
这是调用自定义mongoDB查询的服务方法
public List<UserProfile> getUsersProfile(List<String> emails){
return userProfileRepository.findAllUsersByEmail(emails);
}
这是我的mongoDB存储库接口
public interface UserProfileRepository extends MongoRepository<UserProfile, String>, UserProfileRepositoryCustom {
public UserProfile findByEmail(String email);
}
这是界面
public interface UserProfileRepositoryCustom {
public List<UserProfile> findAllUsersByEmail(List<String> emails);
}
及其实现
public List<UserProfile> findAllUsersByEmail(List<String> emails) {
logger.info("getting all users profiles");
Query query = new Query(where("email").in(emails));
return mongoOperations.find(query, UserProfile.class);
}
当我运行代码时,我在控制器中得到空列表。 findByEmail
运行正常。 谁能帮助我这段代码有什么问题。
问候,
经过更多搜索后,我找到了答案的解决方案,这不是代码问题,实际上是配置问题。 对于那些面临相同问题的人,我将添加解决方案。 添加repository-impl-postfix="CustomImpl"
它开始工作。
之前:
<mongo:repositories base-package="com.app.repositories"/>
之后:
<mongo:repositories base-package="com.app.repositories" repository-impl-postfix="CustomImpl" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.