spring – mongo:存储库不再有效

我有这个配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/data/mongo
      http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <mongo:repositories base-package="com.x.record.persistence.repo"
        mongo-template-ref="mongoTemplate" />

    <context:component-scan base-package="com.x.record.persistence.impl" />

</beans>

在com.x.record.persistence.impl包中,我有一个需要来自com.x.record.persistence.repo的存储库的组件.

这适用于spring-data-mongodb 1.5.2版.RELEASE

如果我升级到大于1.6.0.RELEASE的任何版本(我尝试使用1.6.2和1.7.0),这将不再有效.
好像mongo存储库扫描不起作用,我收到错误:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'noAuthRecordPersistenceService': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.x.record.persistence.repo.RecordRepository com.x.record.persistence.impl.NoAuthRecordPersistenceServiceImpl.repo;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.x.record.persistence.repo.RecordRepository] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

有任何想法吗?

更新:
如果我使用MongoRepository而不是PagingAndSortingRepository它可以工作:

这不起作用(1.6.x及以上):
    公共接口RecordRepository扩展了PagingAndSortingRepository,RecordRepositoryCustom {

Page<Record> findByOrgHierarchy( String orgId, Pageable pageable );

    Record findOneByIdAndOrgHierarchyIn( String id, Collection<String> orgIds );

    int countByGsRunId(String gsRunId);

}

这个工作(1.6.x及以上):
    公共接口RecordRepository扩展了MongoRepository,RecordRepositoryCustom {

Page<Record> findByOrgHierarchy( String orgId, Pageable pageable );

    Record findOneByIdAndOrgHierarchyIn( String id, Collection<String> orgIds );

    int countByGsRunId(String gsRunId);

}

最奇怪的是,我有其他的处理器与PagingAndSortingRepository一起工作

尝试使用示例 here,如果这在最新版本中有效,则可能是您的某些组件仍在使用旧版本,并且可能存在不兼容的状态.

粘贴完整的代码,以便社区可以测试该问题.

相关文章
相关标签/搜索