Micronaut 中的 DI 错误出现在运行时而不是编译时?

DI error in Micronaut shows up in runtime instead of compile time?

我最近做了一个 broken 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 的请求时)中断,而我在使用 Micronaut 时预计会在编译时出现这样的错误。

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

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

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