欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-06-09 15:44:50
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)}

解决方案如图:

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

重新启动,启动成功。

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)}

解决方案:

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

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

相关标签: SpringBoot