开发者

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:

  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.


You can access a thread-bound HttpSession as follows:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜