Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring bean scopes: session and globalSession

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?

like image 636
Shreyos Adikari Avatar asked Mar 14 '13 10:03

Shreyos Adikari


People also ask

What is difference between session and global session scope in Spring?

A global session scope is similar to a session scope. The only difference is that it will be used in a Portlet application. Global sessions can be used when we have an application that is built on the JSR-168, JSR-286, and JSR-362 portal specifications.

What is session scope in Spring?

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 .

What is bean and scope of bean in Spring?

Bean Scopes refers to the lifecycle of Bean that means when the object of Bean will be instantiated, how long does that object live, and how many objects will be created for that bean throughout. Basically, it controls the instance creation of the bean and it is managed by the spring container. Bean Scopes in Spring.


2 Answers

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.

like image 111
partlov Avatar answered Oct 14 '22 17:10

partlov


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.

like image 23
Neha Agarwal Avatar answered Oct 14 '22 18:10

Neha Agarwal