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了。已下附上我的代码图片:
测试错误截图如下:
主程序入口类:
测试正确截图: