What are the Bean scopes in Spring Framework ?

Answered

What are the Bean scopes in Spring Framework ?

Ninja Asked on 17th September 2018 in Spring.
Add Comment
1 Answer(s)
Best answer

The Spring Framework supports five scopes which allow us to control the scope of the bean.

a) singleton – This is the default scope and allows a single instance per Spring IoC container.

b) prototype – Allows a bean to be instantiated any number of times. A distinct instance is provided to everyone who has wiring for this bean.

c) request – Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. This scope is only valid in the context of a web-aware Spring ApplicationContext.

d) session – Scopes a single bean definition to the lifecycle of a HTTP Session. This scope is only valid in the context of a web-aware Spring ApplicationContext.

e) 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.

Ninja Answered on 17th September 2018.
Add Comment