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 1046745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:11:40+00:00 2026-05-16T16:11:40+00:00

I have a singleton spring bean that is being invoked in response to some

  • 0

I have a singleton spring bean that is being invoked in response to some client side action.
I wish to capture some information about the client (specifically the IP address). I assume the best source of this information is the request object. How do I obtain access to the request object from inside my bean?

Forgive me if this is an obvious question, I’m very new to Spring.

I’ve tried one thing without success.:

((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes())
.getRequest().getRemoteAddr();

But that failed with an IllegalStateException out of currentRequestAttributes. The exception text suggests using a RequestContextListener or RequestContextFilter

I’ve found a reference to how to configure the RequestContextListener, but I still don’t know to change my bean so I can access the request information.

  • 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-05-16T16:11:41+00:00Added an answer on May 16, 2026 at 4:11 pm

    RequestContextListener is added to web.xml, and this will associate the current request with the current thread. This thread association is then retrieved via RequestContextHolder in the way you’ve already tried.

    So just slap RequestContextListener into web.xml, and your code should just start working:

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

    RequestContextListener is not normally required in Spring MVC apps, since DispatcherServlet will do it automatically. I assume this is not a Spring MVC app?

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

Sidebar

Related Questions

Assume that we have Spring bean UserController with singleton scope. All my further reasoning
I have a Spring MVC app where I am using a singleton bean that
I have a singleton object that use another object (not singleton), to require some
I've got a singleton Spring bean that creates a couple of tasks ( java.util.concurrent.Callable
I have a spring bean that I have configured in applicationContext like below: <bean
I have a JSF-managed session-scopped bean. It is also a spring component so that
Am new to Spring.I have a spring bean countService which is a singleton public
I have a number of Grails Services that are singleton Spring beans, not prototypes.
I have developed an utility class for spring which is a singleton which will
I have a Singleton to manage some variables I need in various places in

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.