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.