开发者

Spring "session" scope of a bean

It seems to me that "session" scope is another means to keep objects in session as

using setAttrubute / getAttribute

Correct?

You know, dont know why, it does not work for me.

<bean id="sabreUser" class="util.MyUser" factory-method="getSomeUser" scope="session">

<const args...>

What I see is that after the initialization and initial deploy the MyUser properties are correct.

Then, in the first session I change MyUser property, the session is closed.

The second session runs and it sees the last set value from the previous session!

What does that mean?

I expect this object to be initialized whenever a new session starts. But it better looks as singleton, though you see - "session" attribute is set.

I can see the cause of the problem in that a Servlet's fields is initialized with @Autowired so, once it is initialized, every other session will see i开发者_JAVA技巧ts fields set and does not "ReWire" this properties. It happens once? How to overcome this problem?


The Spring session does not exactly match the HttpSession, and even the Spring documentation on the @SessionAttributes annotation says that it might be stored in the session or "some conversational storage". I got that from The Spring docs for 2.5 I've basically quit trying to make sense of it, and just got on with my life, if I want something stored in the HttpSession, I just have Spring inject the HttpSession to me, assuming you're using Spring MVC its pretty easy, instructions on the same page.


Session-scoped beans are beans that live throughout the http session. They are stored in the session via setAttribute in some way.

So - yes.


Session scoped beans are stored in Http Session by Spring framework. This scope is valid only in the context of Web application.It also works for Portlet envionments . When using in Portlet environment, there are two notions of session, application scope and portlet scope (default).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜