我正在使用此配置
<?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一起工作的回购