xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

"ServletScopes.REQUEST already bound" when ServletModule used with Modules.override or PrivateModule #639

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When ServletModules are combined with PrivateModule or Modules.override (for 
test code), Injector creation fails with the binding errors below.

Code to reproduce:

Guice.createInjector(new AbstractModule(){
  @Override
  protected void configure() {
    install(new ServletModule());
    install(new PrivateModule() {
      @Override protected void configure() {
        install(new ServletModule());
      }
    });
  }
});

OR

Guice.createInjector(new AbstractModule(){
  @Override
  protected void configure() {
    install(new ServletModule());
    install(Modules.override(new ServletModule()).with());
  }
});

1) Scope ServletScopes.REQUEST is already bound to 
com.google.inject.servlet.RequestScoped. Cannot bind ServletScopes.REQUEST.
  at com.google.inject.servlet.InternalServletModule.configure(InternalServletModule.java:77)

2) Scope ServletScopes.SESSION is already bound to 
com.google.inject.servlet.SessionScoped. Cannot bind ServletScopes.SESSION.
  at com.google.inject.servlet.InternalServletModule.configure(InternalServletModule.java:78)

3) A binding to javax.servlet.ServletRequest was already configured at 
com.google.inject.servlet.InternalServletModule.configure(InternalServletModule.
java:79).
  at com.google.inject.servlet.InternalServletModule.configure(InternalServletModule.java:79)

... output snipped ..

Original issue reported on code.google.com by jeffjcr...@gmail.com on 5 Jul 2011 at 1:02

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
What's the status of this issue? Guice team doesn't want to fix it or is the 
usage wrong? I also encounter this problem and would someone give some 
workaround/advice for this issue?

Original comment by zhenyu....@gmail.com on 7 Feb 2013 at 6:48

GoogleCodeExporter commented 9 years ago
Unfortunately, the Guice team doesn't cut releases very frequently at all.  I 
would not hold your breath waiting for a bug fix.  We have stopped using 
Modules.override almost completely as this is not the only way that it is 
broken.  (Multibinders also cause it to fail terribly).

Original comment by stevensc...@gmail.com on 7 Feb 2013 at 6:50