Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8900193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:02:55+00:00 2026-06-15T01:02:55+00:00

I am using a RequestContextHolder in a filter to record a piece of data,

  • 0

I am using a RequestContextHolder in a filter to record a piece of data, and want to access it in a POJO (wired up via Spring) later. I’m getting an exception which suggests I’m doing something wrong here, would appreciate any guidance on what that is.

Filter code (in a doFilter() method, whose logging confirms it’s being called):

RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
if (attrs == null)
{
    logger.info("Creating new ServletRequestAttributes");
    attrs = new ServletRequestAttributes(servletRequest);
}

attrs.setAttribute("my_attr", "hello there!", RequestAttributes.SCOPE_REQUEST);

RequestContextHolder.setRequestAttributes(attrs);

POJO code:

RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
if (attrs != null && attrs.getAttribute("my_attr", RequestAttributes.SCOPE_REQUEST) != null)
{
    String myAttr = (String) attrs.getAttribute("my_attr", RequestAttributes.SCOPE_REQUEST);
    logger.debug("Got it: ", myAttr);
}

I am seeing this exception coming from Tomcat though:

java.lang.IllegalStateException: The request object has been recycled and is no longer associated with this facade
    at org.apache.catalina.connector.RequestFacade.getAttribute(RequestFacade.java:259)
    at org.springframework.web.context.request.ServletRequestAttributes.getAttribute(ServletRequestAttributes.java:98)
    at com.mycompany.MyClass(MyClass.java:50)

I do wonder if having the “set data” in a filter, and “get data” via the real work of the request could be in play here, but not sure how best to accommodate that, if it even is relevant?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:02:59+00:00Added an answer on June 15, 2026 at 1:02 am

    The error is likely caused by the fact that you’re making Spring maintain a thread-local handle to a request object that is no longer valid. The details probably don’t matter all that much since a different approach is in order.

    One of the following will take care of automatically setting and clearing thread-local state properly: DispatcherServlet, RequestContextListener or RequestContextFilter. You need to figure out which one makes the most sense for how Spring is used with your app. Your filter and POJO code shouldn’t need to make use of classes like RequestContextHolder directly. What should happen is that you declare a proxied, request-scoped bean for the attribute you want to access:

    <bean id="myAttr" scope="request">
      <aop:scoped-proxy/>
    </bean>
    

    Then, declare the bean for your POJO along with its dependency on the request-scoped bean:

    <bean id="myPojo">
      <property name="myAttr" ref="myAttr"/>
    </bean>
    

    See: Request, session, and global session scopes

    Spring should take care of all the details…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C#, I want to show the image in the Access column but failed
Using a populated Table Type as the source for a TSQL-Merge. I want to
Using Android TelephonyManager an application can obtain the state of data activity over the
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
Using emacs on Ubuntu 11.10. I want to connect to a SQL Server database
Using Core Data, I have a fetch request to fetch the minimum of a
Using Yii, I want to delete all the rows that are not from today.
Using WPF/PRISM I want to log my messages through ILoggerFacade to my GUI (A
Using CMake I want to check if a particular function (cv::getGaborKernel) from OpenCV library
Using batch script, I want to get a first token of a line delimited

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.