解决:UnsatisfiedDependencyException

项目场景:

提示:springboot + mybatis plus


问题描述:

重点报错信息:

  1. Specified class is an interface
  2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bankAllocationDao' defined in file [/...
  3. Unsatisfied dependency expressed through field 'bankDao'
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-05-28 00:01:26.426 [main] ERROR org.springframework.boot.SpringApplication:837 - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bankController': Unsatisfied dependency expressed through field 'bankService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bankServiceImpl': Unsatisfied dependency expressed through field 'bankDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bankDao' defined in file [/.../target/classes/org/.../product/bank/dao/BankDao.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [....dao.BankDao]: Specified class is an interface
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bankServiceImpl': Unsatisfied dependency expressed through field 'bankDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bankDao' defined in file [/.../BankDao.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [...dao.BankDao]: Specified class is an interface
	
	... 20 common frames omitted

原因分析:

大致原因:dao接口无法创建bean,导致service层依赖无法注入,导致controller层依赖无法注入

归根结底:又一个bean创建失败

 

汇总了许多网上的办法:

  1. controller层service层dao层注解是否都使用正确?
  2. 接口有没有写实现类,实现类实现的接口是否正确?
  3. xml映射文件里路径大小写类型是否正确?
  4. 有重复命名的xxxMapper.xml文件吗?
  5. 接口名字是否重复?

解决方案:

最终解决是第五条:接口名字是否重复,但是!重点是:非Spring提供的报错信息中的这个接口与其他重复,而是与报错信息毫无相关的两个接口名字有重复。

如果,前四条检查后没有解决问题,重命名报错中接口名字后仍无见效,请每一个接口的检查,就是这么吐血。

 

  • 32
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Java程序员调优

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值