【问题标题】:How to Diagnose Guice injection errors on code startup如何在代码启动时诊断 Guice 注入错误
【发布时间】:2021-07-28 02:17:40
【问题描述】:

当我使用 Guice Injection 时,我经常犯一些错误。有时问题出在哪里很明显,但似乎 Guice 非常擅长吞下异常并给出相当神秘的错误消息。如:

Exception com.google.inject.CreationException: Unable to create injector, see the following errors:
1) [Guice/ErrorInjectingConstructor]: SomeTerminalException: Creation of SomeService client connection pool failed.
at SomeProvider.<init>(SomeOtherProvider.java:39)
while locating SomeProvider
at YourClientModule.configure(YourClientModule.java:10)
 \_ installed by: SomeModule SomeProvider

我出于法律原因更改了类名,但意图是相同的。

调试这类问题的好方法是什么?

【问题讨论】:

    标签: java dependency-injection guice


    【解决方案1】:

    当堆栈跟踪包含&lt;init&gt; 时,这意味着执行是在构造函数中(请参阅What does <init> signify in a Java exception?)。如错误所示,这发生在SomeOtherProvider.java 的第 39 行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多