蒙戈:库不再工作

问题描述:

我有这个配置蒙戈:库不再工作

<?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需要存储库的组件。

这是工作弹簧数据的MongoDB版本1.5.2.RELEASE

如果我升级到比1.6.0.RELEASE更大的任何版本(我试着用1.6.2和1.7.0)本不再有效。 这是因为如果蒙戈库扫描不工作,我得到的错误:

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)} 

任何想法?

更新: 如果我使用的,而不是PagingAndSortingRepository MongoRepository它的工作原理:

这不起作用(与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及以上): public interface RecordRepository扩展了MongoRepository,RecordRepositoryCustom {

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

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

    int countByGsRunId(String gsRunId); 

} 

的wirdest的事情是,我有做PagingAndSortingRepository

+0

你的noAuthRecordPersistenceService在哪里?这可能是你的上下文:组件扫描太窄,服务没有被spring实例化。 – sfat 2015-05-13 09:22:34

+0

我试过这个配置,它适用于我的两个版本:1.5.X和1.6.X.你可以分享更多的数据:pom.xml,存储库和服务代码等...? – jfcorugedo 2015-05-13 21:40:17

尝试样品here工作的其他回购,如果这是你的一些组件仍使用旧版本和不兼容的状态工作在最新版本,那么其可能可能存在。

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