2015-03-31 125 views
8

我有這個配置蒙戈:庫不再工作

<?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

回答

0

嘗試樣品here工作的其他回購,如果這是你的一些組件仍使用舊版本和不兼容的狀態工作在最新版本,那麼其可能可能存在。

粘貼您的完整代碼,以便社區可以測試該問題。