【问题标题】:DI error in Micronaut shows up in runtime instead of compile time?Micronaut 中的 DI 错误出现在运行时而不是编译时?
【发布时间】:2019-06-18 13:07:21
【问题描述】:

我最近做了一个损坏的 bean,并得到一个似乎与 DI 相关的错误: Message: No bean of type [java.lang.String] exists. Ensure the class is declared a bean and if you are using Java or Kotlin make sure you have enabled annotation processing.

我对我收到错误并不感到惊讶 - 我的 bean 显然坏了。然而,令我惊讶的是它在运行时中断(当发送第一个请求必须实例化损坏的 bean 时),而我在使用 Micronaut 时会在编译时预料到这样的错误。

有问题的 bean 在构造函数上使用 @Inject 注释,而不是在我理解运行时反射成为必要的任何私有字段上。

为什么DI引擎在编译时没有检测到这样的错误?

【问题讨论】:

    标签: java dependency-injection micronaut


    【解决方案1】:

    在编译时不可能知道 bean 不存在。带有 bean 定义的 jar 只能位于运行时类路径中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      相关资源
      最近更新 更多