mongo:存储库不再有效

时间:2015-03-31 14:42:29

标签: spring mongodb

我正在使用此配置

<?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一起工作的回购

1 个答案:

答案 0 :(得分:0)

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

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

相关问题