【问题标题】:Spring changes finding beans from version 4.3 to 5Spring 将查找 bean 从版本 4.3 更改为 5
【发布时间】:2018-09-20 14:04:41
【问题描述】:

我有一个大型 Spring 应用程序,使用在 Spring 4.3.13 中运行良好的注释,并希望更新到 Spring 5。我遇到了各种连接 bean 的故障,看起来很典型:

Unsatisfied dependency expressed through field 'pcoDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.acme.dao.impl.contracts.PotentialChangeOrderDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

开启 spring 调试日志,只增加这一行

Failed to meta-introspect annotation interface org.springframework.beans.factory.annotation.Autowired: java.lang.NullPointerException

并不是所有的@Autowired 字段都失败了,只有这个(到目前为止)。 bean 由接口指定,实现在接口的子包中,但以前也是如此。接口的包直接在 上下文:组件扫描 base-package="com.acme.package.of.interface"

这在 4.3.13 中再次正常工作,唯一的变化是 spring 升级到 5.0.5-RELEASE。

它们对 spring 如何找到 bean 有任何已知的变化吗?或任何有关此的文档?

【问题讨论】:

    标签: java spring dependency-injection


    【解决方案1】:

    似乎是 Spring 5.0.5 的一个 bug,已经在 5.0.6 中修复,见Null check needed in AnnotationUtils.getAnnotation

    【讨论】:

    • 谢谢,看起来很有可能。现在只需要等待 5.0.6,我猜
    • 不是。我从你的回答中节省了很多时间
    【解决方案2】:

    请查看相关接口的实现,如果没有提供实现。 如果有实现,请检查它们是否具有作为@Component 的类级别注释或任何特定注释。 有关自动接线的信息,请阅读this。

    【讨论】:

      猜你喜欢
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-02
      相关资源
      最近更新 更多