2014-02-14 44 views
0

我想使用弹簧数据调用自定义mongoDB查询,但查询没有被调用。调用弹簧数据的自定义mongoDB查询失败

这是我的代码。

在控制器:调用服务方法

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工作正常。任何人都可以帮助我在这段代码中发生什么错误。

问候,

回答

1

寻找多一点之后,我发现了一个解决方案,我的回答,那是不是代码问题,但实际上是配置问题。对于那些面临同样问题的人,我将添加解决方案。加入repository-impl-postfix="CustomImpl"后开始工作。

前:

<mongo:repositories base-package="com.app.repositories"/> 

后:

<mongo:repositories base-package="com.app.repositories" repository-impl-postfix="CustomImpl" />