Monday 17 August 2015

Spring bean scopes – Web application

request:
With this bean scope, a new bean instance will be created for each web request made by client.
As soon as request completes, bean will be out of scope and garbage collected.

session:
Just like request scope, this ensures one instance of bean per user session. As soon as user ends its session, bean is out of scope.

global-session:
global-session 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 you want to store variables global for all portlets in your application than you should store them in global-session.

This scope doesn’t have any special effect different from session scope in Servlet based applications.

In bean configuration file
    xsi:schemaLocation="http://www.springframework.org/schema/beans
  
       <bean id="demoBean" class="com.DemoBean" scope="session" />
  
</beans>

Using annotations
@Service
@Scope("session")
public class DemoBean {
    //Some code
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...