title: How can I get HttpServletRequest in an customized AOP advisor?
body: <p><strong>Context:</strong><br/>
  In my Spring MVC application, I have an advisor that intercepts controller methods (My AOP works fine). In the advice class, I'm trying to extract information by calling HttpServletRequest.getRemoteUser(). Then I need to load user's authorities from DB.<br/>
  <br/><strong>My code</strong><br/>
  Interceptor class (implements <code>MethodInterceptor</code>):</p>
  
  <blockquote>
    <p>private HttpServletRequest request = ((ServletRequestAttributes)<br/>
    RequestContextHolder.currentRequestAttributes()).getRequest();</p>
  </blockquote>
  
  <p>In <code>web.xml</code>:</p>
  
  <pre><code>  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p><strong>Result/Problem</strong>:</p>
  
  <p>I still get <code>java.lang.IllegalStateException: No thread-bound request found</code>, the exception still suggests using <code>RequestContextListener</code> or <code>RequestContextFilter</code>.</p>
  
  <p>I have searched a lot on Stack Overflow and other places but no luck. Any help will be appreciated! (Please bear me for the old question:P)</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I think I am referring to request attributes outside of an actual web request and that's why RequestContextListener doesn't help? </p>
  
  <p>Is there any way I can still get the current request?</p>