项目场景:

提示: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提供的报错信息中的这个接口与其他重复,而是与报错信息毫无相关的两个接口名字有重复。

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

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐