title: Access session scoped variable in spring interceptor
body: <p>How can i access session scoped variable in spring interceptor?</p>
  
  <p>Session scoped class:</p>
  
  <pre><code>@Component
  @Scope("session")
  public class User {
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@Controller
  @RequestMapping("/restricted")
  @Scope("request")
  public class RestrictedController {
      @Autowired
      private User user;
  }
  </code></pre>
  
  <p>Dispatcher servlet:</p>
  
  <pre><code>&lt;mvc:interceptors&gt;
          &lt;mvc:interceptor&gt;
              &lt;mvc:mapping path="/restricted/*"/&gt;
              &lt;bean class="com.interceptors.RestrictedInterceptor" /&gt;
          &lt;/mvc:interceptor&gt;
      &lt;/mvc:interceptors&gt;
  </code></pre>
  
  <p>Interceptor class:</p>
  
  <pre><code>public class RestrictedInterceptor extends HandlerInterceptorAdapter {
  
      @Override
      public boolean preHandle(HttpServletRequest request,
              HttpServletResponse response, Object handler) throws Exception {
      }
  }
  </code></pre>
  
  <p>In prehandle i want to check if user is logged in (some other checks as well), how can i access session scoped user variable here? Autowiring user in Interceptor class throws exception.</p>