What are the different bean scopes in spring

There are 5 bean scopes in spring framework.

  1. singleton
  2. prototype
  3. session
  4. request
  5. globalsession

singleton

The bean instance will be only once and same instance will be returned by the IOC container. It is the default scope.

prototype

The bean instance will be created each time when requested.

session

The bean instance will be created per HTTP session.

request

The bean instance will be created per HTTP request.

globalsession

The bean instance will be created per HTTP global session. It can be used in portlet context only.

 

 

 

No. Scope Description
1) singleton The bean instance will be only once and same instance will be returned by the IOC container. It is the default scope.
2) prototype The bean instance will be created each time when requested.
3) request The bean instance will be created per HTTP request.
4) session The bean instance will be created per HTTP session.
5) globalsession The bean instance will be created per HTTP global session. It can be used in portlet context only.

One thought on “What are the different bean scopes in spring

Leave a comment