title: Scope 'session' is not active for the current thread; IllegalStateException: No thread-bound request found
body: <p>I have a controller that I'd like to be unique per session. According to the spring documentation there are two details to the implementation:</p>
  
  <p><strong>1. Initial web configuration</strong></p>
  
  <blockquote>
    <p>To support the scoping of beans at the request, session, and global session levels (web-scoped beans), some minor initial configuration is required before you define your beans.</p>
  </blockquote>
  
  <p>I've added the following to my <code>web.xml</code> as shown in the documentation:</p>
  
  <pre><code>&lt;listener&gt;
    &lt;listener-class&gt;
      org.springframework.web.context.request.RequestContextListener
    &lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p><strong>2. Scoped beans as dependencies</strong></p>
  
  <blockquote>
    <p>If you want to inject (for example) an HTTP request scoped bean into another bean, you must inject an AOP proxy in place of the scoped bean.</p>
  </blockquote>
  
  <p>I've annotated the bean with <code>@Scope</code> providing the <code>proxyMode</code> as shown below:</p>
  
  <pre><code>@Controller
  @Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
  public class ReportBuilder implements Serializable {
      ...
      ...
  }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>In spite of the above configuration, I get the following exception:</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reportBuilder': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.</p>
  </blockquote>
  
  <p><strong>Update 1</strong></p>
  
  <p>Below is my component scan. I have the following in <code>web.xml</code>:</p>
  
  <pre><code>&lt;context-param&gt;
    &lt;param-name&gt;contextClass&lt;/param-name&gt;
    &lt;param-value&gt;
      org.springframework.web.context.support.AnnotationConfigWebApplicationContext
    &lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;org.example.AppConfig&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>And the following in <code>AppConfig.java</code>:</p>
  
  <pre><code>@Configuration
  @EnableAsync
  @EnableCaching
  @ComponentScan("org.example")
  @ImportResource("classpath:applicationContext.xml")
  public class AppConfig implements AsyncConfigurer {
    ...
    ...
  }
  </code></pre>
  
  <p><strong>Update 2</strong></p>
  
  <p>I've created a reproducible test case. This is a much smaller project, so there are differences, but the same error happens. There's quite a few files, so I've uploaded it as a <code>tar.gz</code> to <a href="http://www.megafileupload.com/en/file/492102/sw-session-scope-tar-gz.html" rel="noreferrer">megafileupload</a>.</p>