Is it possible to set up a Spring session with a bean tag with session attributes?

I am trying to create a service bean that, when referenced, will be initialized with HttpSession based attributes.

Let's say, for the sake of argument, that my webapp will do the following:

  • Establish a session
  • Request username and password
  • When a request is requested (this is scope = "session" and has init-method = "init ()"), a new instance is created for the session.

In the init method, can I refer to the HttpSession either by passing it as a parameter, and referring to it using EL?

Any ideas on this would be appreciated.

+2


source to share


1 answer


You can access the thread related HttpSession

like this:



HttpSession session = 
    (HttpSession) RequestContextHolder.getRequestAttributes()
        .resolveReference(RequestAttributes.REFERENCE_SESSION);

      

+1


source







All Articles