2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Fundamental use of session and global session in Spring

As per my understanding we can configure session in two ways like,

<bean id="exampleBean" class="com.kodetalk.test.baen.ExampleBean" scope="session"/>
<bean id="exampleBean" class="com.kodetalk.test.baen.ExampleBean" scope="globalSession"/>


And the question is , session bean scope will remain till the user session, but will globalSession bean scope available throughout the whole application or is it something like application scope ?

Unable to understand the funda of both the session here. Please someone let me clear these!

userimage


And the Spring documents says that,

  • session - Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.
  • global session - Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.


Which means :

  • globalSession is something which is connected to Portlet applications. When your application works in Portlet container it is built of some amount of portlets. Each portlet has its own session, but if your want to store variables global for all portlets in your application than you should store them in globalSession. This scope doesn't have any special effect different from session scope in Servlet based applications.
Answer is