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

时间:2019-06-18 13:07:21

标签: java dependency-injection micronaut

我最近弄坏了一个豆子,看似与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引擎时(在编译时)未检测到此类错误?

1 个答案:

答案 0 :(得分:1)

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

相关问题