当前位置: 萬仟网 > IT编程>开发语言>Java > SpringBoot测试启动报错Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No quali

SpringBoot测试启动报错Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No quali

2020年07月17日 Java 我要评论
SpringBoot项目中,使用Test类进行启动时,报错如下:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.pojo.Person' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annota

SpringBoot项目中,使用Test类进行启动时,报错如下:

  1. @SpringBootTest(classes = DemoApplicationTests.class)
报错:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.example.demo.DemoApplicationTests': Unsatisfied dependency expressed through field 'person'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.pojo.Person' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.pojo.Person' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方案如图:

重新启动,启动成功。

2.@ComponentScan(basePackages = "com.example.pojo")
java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoApplicationTests': Unsatisfied dependency expressed through field 'person'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.pojo.Person' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方案:

本文地址:https://blog.csdn.net/C__Bill/article/details/107379864

(0)
打赏 微信扫一扫 微信扫一扫

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。

发表评论

验证码:
Copyright © 2017-2022  萬仟网 保留所有权利. 琼ICP备2022007597号