美文网首页
No unique bean of type [com.ufid

No unique bean of type [com.ufid

作者: yahzon | 来源:发表于2019-08-16 16:33 被阅读0次
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<Xxx, String> implements XxxDao {
更新前:
@Repository
public class XxxDaoImpl extends BaseDaoImpl<Xxx, String> implements XxxDao {

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

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

相关文章

网友评论

      本文标题:No unique bean of type [com.ufid

      本文链接:https://www.haomeiwen.com/subject/bmjqsctx.html