Is it possible to configure a Spring session scoped bean with attributes from the session?
I'm trying to create a service bean that when referenced will be initialized with HttpSession based attributes.
Let's say for sake of argument that my webapp would do the following:
- Establish a session
- Request login &开发者_开发问答; password
- When service is requested (it is scope="session" and has init-method="init()") a new instance is created for the session.
In the init method, can I reference the HttpSession either through passing it in as a parameter and referencing it by EL?
Any ideas on this would be appreciated.
You can access a thread-bound HttpSession
as follows:
HttpSession session =
(HttpSession) RequestContextHolder.getRequestAttributes()
.resolveReference(RequestAttributes.REFERENCE_SESSION);
精彩评论