Reputation: 27385
I'm using spring framework and here's the piece of code I'm using to retrieve the HttpSession
object:
ServletRequestAttributes attr;
try {
attr = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
} catch (Exception e) { }
HttpSession session = attr.getRequest().getSession(false);
The thing is RequestContextHolder
Holder class to expose the web request in the form of a thread-bound RequestAttributes object.
therefore it won't be seen outside of the thread created by the container for handling the request. Is there a way to retrieve the session in some child thread?
Upvotes: 0
Views: 1369
Reputation: 10717
No there isn't. In the Servlet API, the session is a property of the request object. Therefore, if you don't have a request, which of the many existing sessions would you retrieve?
Upvotes: 2