当前位置: 移动技术网 > 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日  | 移动技术网IT编程  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网