I’m working on a project that uses Guice 7.0.0 on Java 17 for dependency injection. Recently I’m running into a strange exception when requesting an implementation object for an interface:
com.google.inject.ConfigurationException: Guice configuration errors:
1) [Guice/MissingImplementation]: No implementation for Reals was bound.
Did you mean?
* Reals bound at Bootstrap.bindNativeImplementation(Bootstrap.java:155)
* Provider<Reals> bound at Bootstrap.bindNativeImplementation(Bootstrap.java:155)
My interpretation of this error message (especially the “Did you mean?” part) is that when requesting injection of the Reals
type there is an ambiguity, because it is bound as both Reals
and Provider<Reals>
(but I might misunderstand this).
The line of code that performs the binding is relatively straightforward:
binder.bind(type).to(TypeLiteral.get(implementation)).asEagerSingleton
In the debugger I have verified that this line only gets executed once for the Reals
type, with type
being a TypeLiteral
and implementation
a Class
object.
So, clearly, a binding exists for the type (otherwise the Guice error wouldn’t point to the exact line of code where the implementation was bound), but there is some sort of ambiguity that prevents me from accessing the bound implementation. How can I further debug this?