EugeneP
EugeneP

Reputation: 12003

"session" bean scope in a web application - reliable?

Can you rely on this scope and be sure that every time

1) a new session starts, the Spring bean will be initialized with default values

2) while session is kept alive, the current object will store its state during session life, will never be lost or corrupted and can always be got with [webappcontext].getBean ?

Upvotes: 0

Views: 490

Answers (1)

skaffman
skaffman

Reputation: 403591

  1. Not quite - the Spring bean will be created the first time it is referenced within each new HTTP session. The creation of a new HTTP session will not trigger the immediate creation of every session-scoped Spring bean, that would kill performance. They are initialized lazily, on demand.
  2. Yes

Both are guaranteed. Do you have reason to think otherwise?

Upvotes: 3

Related Questions