-
Notifications
You must be signed in to change notification settings - Fork 1.7k
DUPLICATE_BINDING_ANNOTATIONS
Guice uses
binding annotations
to create unique
Guice keys when
creating bindings. Guice will
throw DUPLICATE_BINDING_ANNOTATIONS error when there are more than one binding
annotation used on a binding.
Example:
final class FooModule extends AbstractModule {
@Qualifier
@Retention(RUNTIME)
@interface Bar {}
@Qualifier
@Retention(RUNTIME)
@interface Baz {}
@Provides
@Bar
@Baz
Foo provideFoo() {
...
}
}Guice will throw a DUPLICATE_BINDING_ANNOTATION error when FooModule is used
because provideFoo has two binding annotations.
It's usually a copy paste error when multiple binding annotations are applied to a single binding. Simply remove all but one binding annotation will fix the error.
If the intention is to create two keys that are bound to the same thing, you can
do so by adding a linked binding using a
@Provides method:
final class FooModule extends AbstractModule {
@Qualifier
@Retention(RUNTIME)
@interface Bar {}
@Qualifier
@Retention(RUNTIME)
@interface Baz {}
@Provides
@Bar
Foo provideFoo() {
...
}
@Provides
@Baz
Foo provideBazFoo(@Bar Foo foo) {
return foo;
}
}With the above example, @Bar Foo and @Baz Foo both bind to the same thing.
-
User's Guide
-
Integration
-
Extensions
-
Internals
-
Releases
-
Community