在我的测试类中,我得到 org.springframework.beans.factory.BeanCreationException: Error created bean with name 'com.abc.service.ExportServiceTest': 自动装配依赖注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 com.bankbazaar.service.ExportService com.abc.service.ExportServiceTest.exportClient;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型为 [com.abc.service.ExportService] 的匹配 bean:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=exportClient)}
这是我的春季配置
然而
exportClient=(ExportService)applicationContext.getBean("exportClient");
这行得通。
谢谢喜芒树