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

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_第1张图片

重新启动,启动成功。

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_第2张图片

你可能感兴趣的:(SpringBoot)