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类进行启动时,报错如下:
-
@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