title: How to inject session scope bean in interceptor using java config with Spring
body: <p>I'm developping a full Spring 3.1 and servlet 3.0 application. But my interceptor has a private properties scoped as proxy:</p>
  
  <pre><code>public class MyInterceptor extends HandlerInterceptorAdapter {
  
      @Ressource
      private UserSession userSession;
  }
  </code></pre>
  
  <p>The user session is defined as:</p>
  
  <pre><code>@Component 
  @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) 
  public class UserSession implements Serializable {
     ....
  }
  </code></pre>
  
  <p>When using this user session in the interceptor, java throws a <code>NullPointerException</code> for <code>userSession</code>.</p>
  
  <p>I think the problem comes from my javaconfig oriented spring configuration:</p>
  
  <pre><code>@EnableWebMvc
  @ComponentScan(basePackages = {"com.whatever"})
  @Configuration
  public class WebAppConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(new MyInterceptor());
      }
  
      ...
  }
  </code></pre>
  
  <p>The problem is that interceptor is manually instantied, so without instrumentation for the session proxy mechanism. Thus, the question is: "how can I let Spring detect and instance the scope session proxy bean in the java config of my application ?</p>