What are different Bean Scopes in Spring?

Carvia Tech | May 05, 2019 at 08:43 AM | 4 views


Spring Framework support total seven scopes, out of which five are available only if you use a web-aware ApplicationContext.

singleton

This is the default scope for any bean. It created a single object instance for a single bean definition per Spring IoC container.

prototype

Any number of object instances can be created for a single bean definition. Everytime we request a bean using getBean() method call on the IoC container, a new instance will be returned.

web-aware Beans Scopes are:

request

Each HTTP request will create its own instance of bean from a single bean definition.

session

Scopes a single bean definition to the lifecycle of an HTTP session.

globalSession

Scopes a single bean definition to the lifecycle of an global HTTP session. Only valid for Portlet context.

application

Scopes a single bean definition to the lifecycle of a ServletContext.

websocket

Scopes a single bean definition to the lifecycle of a WebSocket.


Top articles in this category:
  1. Spring DI - Singleton beans with prototype-bean dependencies
  2. Run method on application startup in Spring Boot
  3. Spring Boot 2.0 Reactive Web Performance Metrics
  4. What is new in Spring Boot 2
  5. How will you handle unresolved circular dependency in spring dependency injection?
  6. How to prevent duplicate form submission in Spring MVC
  7. What is difference between Component, Repository, Service, Controller & RestController


Find more on this topic:
Spring Framework image
Spring Framework

Spring Framework - MVC, Dependency Injection, Spring Hibernate, Spring Data JPA, Spring Boot and Spring Cloud for Microservices Architecture.

Last updated 1 month ago


Recommended books for interview preparation:
You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Spring Microservices Interviews for Java Developers
You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Java Interviews v3.5 by Munish Chandel
You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Spring Microservices Interviews for Java Developers
You may also be interested in..
Generic placeholder image
ebook PDF - Cracking Java Interviews v3.5 by Munish Chandel
Facebook Page
Free Email Updates

Enter your email address to subscribe to this blog and receive notifications of new posts by email.


This website uses cookies to ensure you get the best experience on our website. more info