SpringBoot单元测试依赖注入失败

时间:2024-05-20 12:26:22

依赖注入问题。

    当时做项目是要去加载一个外部空间,一些固定变量存到配置文件

SpringBoot单元测试依赖注入失败

 

然后单元测试的时候,一直报报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sunnada.gaia.data.web.AutomaticSealTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sunnada.gaia.data.web.controller.construction.AutomaticStampController' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

,注入失败,没有这个类型,懵逼了一晚上,后面发现是在这个类里我写了一个测试方法(@Test),就是这个问题,导致单元测试注入失败,