简体   繁体   English

春季:未找到符合自动装配条件的匹配豆

[英]Spring: No matching bean found which qualifies as autowire

Application-Context is correctly setup! 应用程序上下文已正确设置!

Heres my class scenario 这是我班的情景

public interface IManager
{
 public void doStuff();
}

@Component
public abstract class ManagerAction implements IManager
{
  @Async
  @Override
  public void doStuff()
  {
     //doing stuff
  }

  public abstract manageWorker();
}

@Component
public class Working extends ManagerAction
{
  @Override
  public manageWorker()
  {
    //some busy code
  }
}

@Component
public class NotWorking extends ManagerAction
{
  @Override
  public manageWorker()
  {
    //some busy code
  }
}

@Service
public class BusinessWorker
{
  @Autowire
  private IManager manager_;

  public void preformTasks()
  {    
    manager_.doStuff();
  }
}

Heres my error 这是我的错误

ERROR [main] (ContextLoader.java:307) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'BusinessWorker': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.B
eanCreationException: Could not autowire field: private com.background.IManager com.background.BusinessWorker.manager_; nested exception is org.springframework.beans.
factory.NoSuchBeanDefinitionException: No matching bean of type [com.background.IManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for
 this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.background.IManager com.background.BusinessWorker.manager_; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.background.IManager] found for dependency: expected at least 1 
bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    ... 28 more

Application-Context 应用上下文

<mvc:annotation-driven />
<task:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.background" />

The error message says it all: you try to autowire an instance of IManager, but two different Spring components implement this interface, so Spring doesn't know which one to autowire. 错误消息说明了一切:您尝试自动装配IManager实例,但是两个不同的Spring组件实现了此接口,因此Spring不知道要自动装配哪个。 You need to use the @Qualifier annotation to specify which one you want Spring to autowire. 您需要使用@Qualifier批注指定您要Spring自动装配的那个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有匹配的 bean 类型……为依赖找到……预计至少有 1 个符合自动装配候选者的 bean - No matching bean of type … found for dependency....expected at least 1 bean which qualifies as autowire candidate 找不到相依路径类型为path.repositoryClass的相符bean,至少应有1个符合此相依条件的自动装配候选 - No matching bean of type path.repositoryClass found for dependency expected at least 1 bean which qualifies as autowire candidate for this dependency Spring 预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者 - Spring expected at least 1 bean which qualifies as autowire candidate for this dependency Spring @Autowired 不工作 - 预计至少有 1 个 bean 有资格作为 autowire 候选 - Spring @Autowired not working - expected at least 1 bean which qualifies as autowire candidate Spring @Resource期望至少有1个bean符合此依赖项的自动装配条件 - Spring @Resource Expected at least 1 bean which qualifies as autowire candidate for this dependency 没有为依赖项找到UserRepository类型的限定bean:预期至少有1个bean符合此依赖项的autowire候选者 - No qualifying bean of type UserRepository found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency 未找到依赖项的类型为[PATHTOCLASS]的合格Bean:至少应有1个符合此依赖项自动候选条件的Bean - No qualifying bean of type [PATHTOCLASS] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency 未找到依赖项[**。Clients]的合格bean:至少应有1个合格为autowire候选对象的bean。 依赖注释:{} - No qualifying bean found for dependency [**.Clients]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} Crudrepository - 没有为依赖找到符合条件的 bean:预计至少有 1 个 bean 有资格作为这个依赖的自动装配候选者 - Crudrepository - No qualifying bean of type found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency 没有找到依赖 [CountryRepository] ​​的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选 - No qualifying bean found for dependency [CountryRepository]: expected at least 1 bean which qualifies as autowire candidate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM