question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading error message with child injector

See original GitHub issue

If you have a child injector and ask the parent injector a value for a binding defined in the child, you get an “It was already configured on one or more child injectors” error.

It would be better to say “No implementation for … was bound, although it is configured in a child injector”.

Here’s a sample code:

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;

public class GuiceBug {

    public static void main(String[] args) {
        Injector i1 = Guice.createInjector();
        Injector i2 = i1.createChildInjector(
                new AbstractModule() {
                        @Override
                        protected void configure() {
                            bind(IStuff.class).to(Stuff.class);
                        }
                    });
        i1.getInstance(IStuff.class);
    }

    static interface IStuff {}

    static class Stuff implements IStuff {}
}
Exception in thread "main" com.google.inject.ConfigurationException: Guice configuration errors:

1) Unable to create binding for org.enercoop.test.GuiceBug$IStuff. It was already configured on one or more child injectors or private modules
    bound at org.enercoop.test.GuiceBug$1.configure(GuiceBug.java:15)
  If it was in a PrivateModule, did you forget to expose the binding?
  while locating org.enercoop.test.GuiceBug$IStuff

1 error
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004)
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:961)
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
    at GuiceBug.main(GuiceBug.java:18)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:8
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
prdoylecommented, Mar 27, 2017

I can’t help but think @laurentmartelli was right about this error.

  • With my bind call, I get this error
  • If I comment out my bind call, I get “No implementation forwas bound

How can I have too many bindings, then remove one binding, and then not have enough?

7reactions
matveyshishovimanagecommented, Nov 29, 2018

It was confusing for me as well, googling this discussion turned out the fastest way to find the actual cause, so the message could just as well have a link to this discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[guice] Misleading error message with child injector (#877)
If you have a child injector and ask the parent injector a value for a binding defined in the child, you get an...
Read more >
Crazy ChildInjector-related Exception - Google Groups
The scenario is: We create a parent injector for the core and a child injector for the UI. The child injector has an...
Read more >
Re: Child injector causes Guice configuration errors - The Mail Archive
I get the same type of error > message: "It was already configured on one or more child > injectors or private modules"....
Read more >
Injectors • Angular - codecraft.tv
Child injectors forward requests to their parent injector if they can't resolve the token locally. TypeScript. Copy import { ReflectiveInjector } from '@angular ......
Read more >
Introduction to services and dependency injection - Angular
In Angular, dependency injection makes those services available to components. ... export class Logger { log(msg: any) { console.log(msg); } error(msg: any) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found