- How we can set the spring bean scope. And what supported scopes does it have?
 
The Spring Framework supports six scopes for beans:
- Singleton
 - Prototype
 - Request
 - Session
 - Global session
 - Custom
 
The default scope is singleton. In this scope, a single instance of the bean is created and shared by all consumers. This is the most common scope to use for beans that are not thread-safe.
The prototype scope creates a new instance of the bean for each consumer. This is useful for beans that are thread-safe or that need to be independent of each other.
The request scope creates a new instance of the bean for each HTTP request. This is useful for beans that are only needed for the duration of a request.
The session scope creates a new instance of the bean for each HTTP session. This is useful for beans that need to be associated with a particular user session.
The global session scope is similar to the session scope, but it is only available in a portlet environment.
The custom scope allows you to define your own scope. This can be useful for beans that require a specific lifecycle.
To set the scope of a bean, you can use the @Scope annotation. For example, the following annotation defines a bean with the prototype scope:
@Scope(value = "prototype")
public class MyBean {
...
}
You can also set the scope of a bean in XML configuration. For example, the following XML snippet defines a bean with the singleton scope:
<bean id="myBean" class="com.example.MyBean" scope="singleton"> ... </bean>
