Spring bean scopes: session and globalSession

北战南征 提交于 2019-12-03 02:34:43

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15407038/spring-bean-scopes-session-and-globalsession

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!