我有这个配置
<?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 及更高版本): 公共(public)接口(interface) 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);
}
最奇怪的是我还有其他可以与 PagingAndSortingRepository 一起使用的存储库
最佳答案
试用 sample here ,如果这在最新版本中有效,那么您的某些组件可能仍在使用旧版本并且可能存在不兼容状态。
粘贴您的完整代码,以便社区可以测试问题。
关于spring - 蒙戈 : repositories no longer works,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29371411/