【问题标题】:When "No qualifying bean of type found for dependency" is ok当“没有找到依赖类型的合格 bean”是可以的
【发布时间】:2014-08-08 00:52:15
【问题描述】:

我创建了一个 bean,它期望注入给定类型的所有 bean... 像这样:

public class MyClass {
  private List<MyOtherBean> myOtherBeansList;
  ....
  @Inject
  public void setMyOtherBeanList(List<MyOtherBean> otherBeanList) {
    this.myOtherBeansList = otherBeanList;
  }

这很好用,除非我没有定义“MyOtherBeans”类型的 bean。在我的业务逻辑中,没关系!但是spring不喜欢,抛出了过于熟悉的:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type...

异常。有谁知道在这种情况下让 spring 传递给我 null 的方法?

【问题讨论】:

标签: spring


【解决方案1】:

没关系..我很笨。

@Autowired(required=false)

【讨论】:

  • 是的,你是对的。 Inject 和 Autowired 在行为上是同义词,所以我只是假设。我已经在我的代码中切换到 Autowired 以尝试解决问题,并且没有费心检查 Inject。过错。已编辑。
  • 有关我的错误的更多信息,另请参阅here
猜你喜欢
  • 2015-01-29
  • 2016-12-31
  • 2018-12-02
  • 2016-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多