Error creating bean with name 'XXX': Injection of autowired dependencies failed解决办法

电玩女神 2021-12-14 08:19 595阅读 0赞

使用SpringMVC框架,这条完整的error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘accountCtrl’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.bing.mapper.wxcms.service.AccountService com.bing.mapper.wxcms.ctrl.AccountCtrl.accountService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.bing.mapper.wxcms.service.AccountService] 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)}

报错中异常为NoSuchBeanDefinitionException,指出没有找到要注入的内容(service或dao),从两方面着手:

1、检查下在spring配置中,是否将对应的包加入扫描。

dao配置:






扫描service包下所有使用注解的类型

2、检查对应的注解有没有加上,可能没加@service

@Service
public class AccountServiceImpl implements AccountService {

  1. @Autowired
  2. private AccountDao accountDao;
  3. public List<Account> listForPage(Account searchEntity) \{
  4. return accountDao.listForPage(searchEntity);
  5. \}

}

-——————————
作者:夏日踩冰
来源:CSDN
原文:https://blog.csdn.net/a411358606/article/details/54426424

发表评论

表情:
评论列表 (有 0 条评论,595人围观)

还没有评论,来说两句吧...

相关阅读