title: Scope 'session' is not active for the current thread
body: <p>I have two Spring applications: client and server. On server application are services, on client app is view logic. Both apps should communicate through web-services, but this did not work because of error</p>
  
  <blockquote>
    <p>Request processing failed; nested exception is
    org.springframework.remoting.jaxws.JaxWsSoapFaultException: Error
    creating bean with name 'scopedTarget.jcrSession': 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>On server app i'm using JCR Session (session scoped bean)</p>
  
  <pre><code>&lt;bean name="jcrSession" factory-bean="sessionFactory" factory-method="login" scope="session" destroy-method="logout" &gt;
      &lt;aop:scoped-proxy/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>in web.xml of server app I have</p>
  
  <pre><code>&lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>When I access WSDL files produced by server app in browser, everything is OK. When I use server app services locally (e.g. in controller on server app) everything is also OK. So why this error occurs, when I try to access services through web-services from remote app?</p>
  
  <p><strong>Update1</strong>
  <code>jcrSession</code> is crated by <code>SessionFactory</code> class. Then this <code>jcrSession</code> is autowired to DAO objects using springs <code>@Autowired</code>.</p>
  
  <pre><code>Example of simplified `JcrSessionFactory`:
  public class JcrSessionFactory {
  
      private Repository repository;
      private Credentials credentials;
      private Session session;
  
      public Session login() {
          session = repository.login(credentials);
          return session;
      }
  
      public void logout() {
          session.logout();
      }
  }
  </code></pre>
  
  <p>Also, same error occured when I tried to autowire service in same app and use it in method annotated by <code>@PostConstruct</code> or in implementation of <code>InitializingBean</code> in method <code>afterPropertiesSet()</code></p>