java - 存储库接口的 Spring Data MongoDb bean xml 配置
问题描述
xml
我有一个使用配置的现有 spring 应用程序。现在,我将使用spring-data-mongodb
它连接到 Mongo 数据库。我repository/dao
的都是这样的接口:
public interface CustomerDao extends MongoRepository<Customer, String> {
...
}
在我的服务类CustomerService
中,它自动装配CustomerDao
接口。
<bean id="customerDao" class="com.myapp.repository.CustomerDao" />
<bean id="customerService" class="com.myapp.service.CustomerService">
<property name="customerDao" ref="customerDao"/>
</bean>
但由于CustomerDao
是一个接口,我总是收到错误:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.myapp.repository.CustomerDao]: Specified class is an interface
基于spring-data-mongodb
存储库的教程主要是扩展至MongoRepository
.
我的问题是,如果我不在配置中创建 bean 条目,则在类CustomerDao
内部自动装配时会出错。以下是我得到的错误:CustomerService
xml
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.myapp.repository.CustomerDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=customerDao)}
解决方案
推荐阅读
- scikit-learn - 混淆矩阵 - 样本数量不一致的变量
- mysql - 如何解决在mysql中创建表的问题?
- python-3.x - 如何使用 cx_Oracle 在一个变量中按顺序执行多个 DML 语句
- groovy - 将 Jenkinsfile 中属性文件的值替换为动态设置的变量
- python - 初始化布尔值的 Pythonic 方法
- python - 如何将数据发布到 Django REST API
- python - 为什么我的变量以蓝色突出显示?
- multithreading - 找出哪些线程拥有 pthread_rwlock_t
- excel-formula - 计算一个范围内的序列数
- facebook - 如何使用 IBM Watson Assistant 对话框制作 Messenger Facebook 的通用模板