No unique bean of type [com.ufida.dao.BaseDao]

Error creating bean with name 'xxxServiceImpl': Injection of resource methods failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ufida.dao.BaseDao] is defined: expected single matching bean but found 40

报错分析:
spring 组装bean的时候,匹配到多个类。
因为Dao层的实现类都继承了 baseDao
这个错误在jdk1.6不出现,升级到jdk1.8 后出现。
解决:
1、xxxDaoImpl 注解中添加名称:

更新后:
@Repository("xxxDao")
public class XxxDaoImpl extends BaseDaoImpl implements XxxDao {
更新前:
@Repository
public class XxxDaoImpl extends BaseDaoImpl implements XxxDao {

2、setBaseDao()方法的注解上指定name属性

更新后:
@Service
public class XxxServiceImpl extends BaseServiceImpl implements XxxService {
    
    @Resource(name="viewProductDao")
    public void setBaseDao(ViewProductDao viewProductDao) {
        super.setBaseDao(viewProductDao);
    }
更新前:
@Service
public class XxxServiceImpl extends BaseServiceImpl implements XxxService {
    
    @Resource
    public void setBaseDao(ViewProductDao viewProductDao) {
        super.setBaseDao(viewProductDao);
    }

你可能感兴趣的:(No unique bean of type [com.ufida.dao.BaseDao])