我正在尝试使用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
工作正常。任何人都可以帮助我在这段代码中出错。
此致
答案 0 :(得分:1)
在搜索了一下之后,我找到了我的答案的解决方案,这不是代码问题,而是实际上是配置问题。对于那些面临同样问题的人,我将添加解决方案。添加repository-impl-postfix="CustomImpl"
后,它开始工作。
之前:
<mongo:repositories base-package="com.app.repositories"/>
之后:
<mongo:repositories base-package="com.app.repositories" repository-impl-postfix="CustomImpl" />