• The following options can be used to implement an HttpSession in spring applications
  1. Injecting HttpSession
    – Inject HttpSession wherever required
    – Retrieving and saving data in the session has to be managed manually

Example: Injecting HttpSession

2. Accept it as a parameter
– Useful for web tire applications

Example: Accept as Parameter

Spring Session Management (Cont’d)

3. Creating Bean with session scope
– Retrieving and saving changes to the Bean is taken care by spring
– Spring Lifecycle methods(@PostConstruct or @PreDestroy annotated annotated methods) defined in the Bean will be implemented automatically

Example: Creating Session scope Bean

4. Using @SessionAttributes annotation
– Include @SessionAttributes annotation for model attributes to be stored in the session
-@SessionAttributes copies the specifed model attributes to Httpsession before rendering the view

Example: Using @Sission rendering the view