In this video, we are going to discuss about the @Scope.
@Scope | singleton scope | prototype scope | request scope | session scope | global session | application scope
Spring Annotation
Spring Boot Annotation
learn to use @Scope annotation in spring boot.
- Spring Framework provides a @Scope annotation that can be used to define the scope of a bean.
The scope of a bean determines the lifecycle and visibility of the bean instances managed by the Spring IoC (Inversion of Control) container.
Type of Scopes:
---------------------------------------
Singleton (@Scope("singleton")): This is the default scope. It means that only one instance of the bean will be created for the entire Spring container.
It is suitable for stateless and stateful beans that can be safely shared.
Prototype (@Scope("prototype")): A new instance of the bean is created every time it is requested.
It is suitable for stateful beans or when you want to control the lifecycle of the bean explicitly
Request (@Scope("request")): A new instance of the bean is created for each HTTP request. This is valid only in the context of a web-aware Spring ApplicationContext.
Session (@Scope("session")): A new instance of the bean is created for each HTTP session. Like the request scope, this is applicable in web applications.
Global Session (@Scope("globalSession")): Similar to the session scope, but used for portlet-based web applications.
Application (@Scope("application")): A single instance of the bean is created for each ServletContext.
Last four scopes mentioned- request, session, application and global are only available in a web-aware application.
Негізгі бет What is @Scope Annotation? Singleton vs Prototype Scope -Spring & Spring Boot Annotations Series #10
Пікірлер: 1