views:

91

answers:

1

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:

  1. Establish a session
  2. Request login & password
  3. 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.

+1  A: 

You can access a thread-bound HttpSession as follows:

HttpSession session = 
    (HttpSession) RequestContextHolder.getRequestAttributes()
        .resolveReference(RequestAttributes.REFERENCE_SESSION);
axtavt
Thanks for the answer axtavt. Unfortunately the API you've referenced does not match what is in the documentation. I found http://stackoverflow.com/questions/1629211/how-do-i-get-the-session-object-in-spring which got me much closer to where I need to be.Thanks for your input!
Dave G