spring - Scope 'session' is not active for the current thread; IllegalStateException: No thread-bound request found -


i have controller i'd unique per session. according spring documentation there 2 details implementation:

1. initial web configuration

to support scoping of beans @ request, session, , global session levels (web-scoped beans), minor initial configuration required before define beans.

i've added following web.xml shown in documentation:

<listener>   <listener-class>     org.springframework.web.context.request.requestcontextlistener   </listener-class> </listener> 

2. scoped beans dependencies

if want inject (for example) http request scoped bean bean, must inject aop proxy in place of scoped bean.

i've annotated bean @scope providing proxymode shown below:

@controller @scope(value="session", proxymode=scopedproxymode.target_class) public class reportbuilder implements serializable {     ...     ... } 

problem

in spite of above configuration, following exception:

org.springframework.beans.factory.beancreationexception: error creating bean name 'scopedtarget.reportbuilder': scope 'session' not active current thread; consider defining scoped proxy bean if intend refer singleton; nested exception java.lang.illegalstateexception: no thread-bound request found: referring request attributes outside of actual web request, or processing request outside of receiving thread? if operating within web request , still receive message, code running outside of dispatcherservlet/dispatcherportlet: in case, use requestcontextlistener or requestcontextfilter expose current request.

update 1

below component scan. have following in web.xml:

<context-param>   <param-name>contextclass</param-name>   <param-value>     org.springframework.web.context.support.annotationconfigwebapplicationcontext   </param-value> </context-param>  <context-param>   <param-name>contextconfiglocation</param-name>   <param-value>org.example.appconfig</param-value> </context-param>  <listener>   <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> 

and following in appconfig.java:

@configuration @enableasync @enablecaching @componentscan("org.example") @importresource("classpath:applicationcontext.xml") public class appconfig implements asyncconfigurer {   ...   ... } 

update 2

i've created reproducible test case. smaller project, there differences, same error happens. there's quite few files, i've uploaded tar.gz megafileupload.

the problem not in spring annotations design pattern. mix different scopes , threads:

  • singleton
  • session (or request)
  • thread pool of jobs

the singleton available anywhere, ok. session/request scope not available outside thread attached request.

asynchronous job can run request or session doesn't exist anymore, not possible use request/session dependent bean. there no way know, if running job in separate thread, thread originator request (it means aop:proxy not helpful in case).


i think code looks want make contract between reportcontroller, reportbuilder, uselesstask , reportpage. there way use simple class (pojo) store data uselesstask , read in reportcontroller or reportpage , do not use reportbuilder anymore?


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -