Spring bean scopes: session and globalSession

JavaSpringSpring MvcSpring Ioc

Java Problem Overview


What is the difference between session and globalSession in Spring framework?

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

As per my study, both are valid in the context of a web-aware Spring ApplicationContext.

Now, session bean scope will remain until the user session, but will globalSession bean scope be available throughout the whole application?

Is it the application scope?

I am unable to understand the term "global HTTP Session"; will it be available throughout the global HTTP Session?

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

As per Spring documentation ::

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.

Solution 3 - Java

Session scope adds bean definiton of a http session, valid only in application context. a new bean will be created for each http session by the conntainer. Global session scope adds bean definiton of a global http session used in portlet application context.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShreyos AdikariView Question on Stackoverflow
Solution 1 - JavapartlovView Answer on Stackoverflow
Solution 2 - JavaNeha AgarwalView Answer on Stackoverflow
Solution 3 - JavaBhanuView Answer on Stackoverflow