SpringBoot测试时报错:

        Positive matches: 此处省略一些乱七八糟的错误:最后有一个引起错误的原因:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.yb.entity.Person' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

报错的原因应该是没有找到bean,具体的原因是:主程序类和其他业务逻辑类不在一个包下,SpringBoot没有扫描到,所以,解决的方法应该是在: SpringBoot的主程序入口类加上:@ComponentScan(basePackages = "XXX.XXX"),在此运行测试程序就OK了。已下附上我的代码图片:

测试错误截图如下:

SpringBoot测试时报错:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean

 主程序入口类:

    SpringBoot测试时报错:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean

测试正确截图:

SpringBoot测试时报错:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean

       

相关文章:

  • 2021-11-09
  • 2021-06-02
  • 2022-12-23
  • 2021-10-08
  • 2021-11-01
  • 2022-12-23
  • 2021-10-01
  • 2022-01-03
猜你喜欢
  • 2021-08-06
  • 2021-09-04
  • 2021-08-04
  • 2021-04-09
  • 2021-06-22
  • 2021-07-01
  • 2021-04-30
相关资源
相似解决方案