title: Guice: Injecting Interceptors in ServletModule
body: <p>I am trying to inject an Interceptor with a Vaadin Application instance created by Guice. 
  I've followed the documentation for Vaadin-Guice integration in the <a href="https://vaadin.com/wiki/-/wiki/Main/Integrating%20Vaadin%20with%20Guice%202.0?p_r_p_185834411_title=Integrating%2520Vaadin%2520with%2520Guice%25202.0" rel="nofollow">Vaadin Wiki</a> and 
  the documenation on Interceptor DI in the <a href="http://code.google.com/p/google-guice/wiki/AOP#Injecting_Interceptors" rel="nofollow">Guice Wiki</a>:</p>
  
  <pre><code>public class RecruitmentServletConfig extends GuiceServletContextListener {
  
      @Override
      protected Injector getInjector() {
  
          ServletModule servletModule = new ServletModule() {
  
              @Override
              protected void configureServlets() {
                  ...
                  bind(Application.class).to(RecruitmentApplication.class).in(ServletScopes.SESSION);
                  SecurityGuard securityGuard = new SecurityGuard();
                  requestInjection(securityGuard);
                  bindInterceptor(Matchers.subclassesOf(CustomComponent.class), Matchers.annotatedWith(AllowedRoles.class), securityGuard);
              }
          };
          return Guice.createInjector(servletModule);
      }
  }
  </code></pre>
  
  <p>The SecurityGuard interceptor:</p>
  
  <pre><code>public class SecurityGuard implements MethodInterceptor {
      @Inject private Application application;
  
      public Object invoke(MethodInvocation invocation) throws Throwable {
          AllowedRoles allowedRoles = invocation.getMethod().getAnnotation(AllowedRoles.class);
          if (((User) application.getUser()).hasRole(allowedRoles.value())) {
              return invocation.proceed(); 
          } else {
              return null;
          }
  }
  </code></pre>
  
  <p>However, I get an OutOfScopeException on server startup:</p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class de.embl.eicat.recruit.ioc.RecruitmentServletConfig
  com.google.inject.CreationException: Guice creation errors:
  1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped object. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
  at recruit.ioc.RecruitmentServletConfig$1.configureServlets(RecruitmentServletConfig.java:86)
  </code></pre>