-
Notifications
You must be signed in to change notification settings - Fork 1.7k
DUPLICATE_SCOPES
Googler edited this page Aug 13, 2020
·
1 revision
Guice will throw a DUPLICATE_SCOPES
error if
a scope annotation
is
registered
to more than one implementation.
Example:
import com.google.inject.servlet.RequestScoped;
final class MyRequestScopeModule extends AbstractModule {
@Override
protected void configure() {
MyRequestScope scope = new MyRequestScope();
bindScope(RequestScoped.class, scope);
}
}
When the above module is installed in the same injector as Guice's
ServletModule
, which also registers an implementation for RequestScoped
,
Guice will throw a DUPLICATE_SCOPES
error:
import com.google.inject.servlet.ServletModule;
final class ApplicationModule extends AbstraceModule {
@Override
protected void configure() {
install(new MyRequestScopeModule());
...
// ServletModule also registers `RequestScoped` scope.
install(new ServletModule());
}
}
In the example in summary section, RequestScoped
is being
registered multiple times. To fix this type of error, you can either:
- Remove all but one implementation of the scope.
- Or, use a different scope annotations for each scope implementation.
If a scope is registered in FooModule
and FooModule
is installed more than
once in the injector then a DUPLICATE_SCOPES
(and maybe many other Guice
errors) will be thrown. So make sure that FooModule
is only installed once.
-
User's Guide
-
Integration
-
Extensions
-
Internals
-
Releases
-
Community