【发布时间】: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