解决:UnsatisfiedDependencyException
·
项目场景:
提示:springboot + mybatis plus
问题描述:
重点报错信息:
- Specified class is an interface
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bankAllocationDao' defined in file [/...
- 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创建失败
汇总了许多网上的办法:
- controller层service层dao层注解是否都使用正确?
- 接口有没有写实现类,实现类实现的接口是否正确?
- xml映射文件里路径大小写类型是否正确?
- 有重复命名的xxxMapper.xml文件吗?
- 接口名字是否重复?
解决方案:
最终解决是第五条:接口名字是否重复,但是!重点是:非Spring提供的报错信息中的这个接口与其他重复,而是与报错信息毫无相关的两个接口名字有重复。
如果,前四条检查后没有解决问题,重命名报错中接口名字后仍无见效,请每一个接口的检查,就是这么吐血。
更多推荐
已为社区贡献2条内容
所有评论(0)