java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter

Spring JIRA | Erik Pilz | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    [SPR-2448] Provide a better error message for scope wiring problems - Spring JIRA

    spring.io | 1 year ago
    java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter
  2. 0

    The error messages that are logged because of scope wiring problems could be improved. Here's a short example illustrating the typical problem I keep seeing: <bean id="fileCabinet" class="com.example.cabinet.FileCabinet"> <property name="remoteUser" ref="remoteUser" /> </bean> <bean id="remoteUser" class="com.example.user.RemoteUser" scope="session" /> The developer in this case has written an application-scoped bean, FileCabinet, and needs a handle to the current user to set audit properties on a file that is being updated. The error that is printed when the application server starts is as follows: ---- Begin log excerpt --- 2006-08-18 17:08:07,295 ERROR [springframework.web.context.ContextLoader] Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileCabinet' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'remoteUser' while setting bean property 'remoteUser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'remoteUser': Scope 'session' is not active; nested exception is java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'remoteUser': Scope 'session' is not active; nested exception is java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter Caused by: java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:62) at org.springframework.web.context.request.SessionScope.get(SessionScope.java:80) at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:62) at org.springframework.web.context.request.SessionScope.get(SessionScope.java:80) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:276) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:155) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:246) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:850) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:624) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:411) ---- End log excerpt ---- Usually I find a very confused developer scratching her head and looking at a web.xml file at this point. Two simple options to better handle this are: 1) modify the current error message to include other potential causes other than just a problem with the filter/listener in the web.xml file; or, 2) throw an exception when the reference is being resolved.

    Spring JIRA | 1 decade ago | Erik Pilz
    java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter
  3. 0

    The error messages that are logged because of scope wiring problems could be improved. Here's a short example illustrating the typical problem I keep seeing: <bean id="fileCabinet" class="com.example.cabinet.FileCabinet"> <property name="remoteUser" ref="remoteUser" /> </bean> <bean id="remoteUser" class="com.example.user.RemoteUser" scope="session" /> The developer in this case has written an application-scoped bean, FileCabinet, and needs a handle to the current user to set audit properties on a file that is being updated. The error that is printed when the application server starts is as follows: ---- Begin log excerpt --- 2006-08-18 17:08:07,295 ERROR [springframework.web.context.ContextLoader] Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileCabinet' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'remoteUser' while setting bean property 'remoteUser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'remoteUser': Scope 'session' is not active; nested exception is java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'remoteUser': Scope 'session' is not active; nested exception is java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter Caused by: java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:62) at org.springframework.web.context.request.SessionScope.get(SessionScope.java:80) at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:62) at org.springframework.web.context.request.SessionScope.get(SessionScope.java:80) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:276) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:155) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:246) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:850) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:624) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:411) ---- End log excerpt ---- Usually I find a very confused developer scratching her head and looking at a web.xml file at this point. Two simple options to better handle this are: 1) modify the current error message to include other potential causes other than just a problem with the filter/listener in the web.xml file; or, 2) throw an exception when the reference is being resolved.

    Spring JIRA | 1 decade ago | Erik Pilz
    java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Hystrix stopped working behind Zuul Proxy

    GitHub | 2 years ago | NickPadilla
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.oauth2ClientContext': 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.
  6. 0

    Exception thrown in EventBus.unsubscribe after close a browser window

    GitHub | 3 years ago | LukaszByczynski
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sessionEventBus': 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.

  1. Andreas Häber 1 times, last 4 months ago
  2. serious2monkeys 6 times, last 7 months ago
4 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.IllegalStateException

    No thread-bound request: use RequestContextFilter

    at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes()
  2. Spring
    SessionScope.get
    1. org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:62)
    2. org.springframework.web.context.request.SessionScope.get(SessionScope.java:80)
    3. org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:62)
    4. org.springframework.web.context.request.SessionScope.get(SessionScope.java:80)
    4 frames
  3. Spring Beans
    AbstractAutowireCapableBeanFactory.createBean
    1. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:276)
    2. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:155)
    3. org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:246)
    4. org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
    5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:850)
    6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:624)
    7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:411)
    7 frames