Strategy interface used by a {@link ConfigurableBeanFactory}, representing a target scope to hold bean instances in. This allows for extending the BeanFactory's standard scopes {@link ConfigurableBeanFactory#SCOPE_SINGLETON "singleton"} and{@link ConfigurableBeanFactory#SCOPE_PROTOTYPE "prototype"}with custom further scopes, registered for a {@link ConfigurableBeanFactory#registerScope(String,Scope) specific key}.
{@link org.springframework.context.ApplicationContext} implementationssuch as a {@link org.springframework.web.context.WebApplicationContext}may register additional standard scopes specific to their environment, e.g. {@link org.springframework.web.context.WebApplicationContext#SCOPE_REQUEST "request"}and {@link org.springframework.web.context.WebApplicationContext#SCOPE_SESSION "session"}, based on this Scope SPI.
Even if its primary use is for extended scopes in a web environment, this SPI is completely generic: It provides the ability to get and put objects from any underlying storage mechanism, such as an HTTP session or a custom conversation mechanism. The name passed into this class's get
and remove
methods will identify the target object in the current scope.
Scope
implementations are expected to be thread-safe. One Scope
instance can be used with multiple bean factories at the same time, if desired (unless it explicitly wants to be aware of the containing BeanFactory), with any number of threads accessing the Scope
concurrently from any number of factories.
@author Juergen Hoeller
@author Rob Harrop
@since 2.0
@see ConfigurableBeanFactory#registerScope
@see CustomScopeConfigurer
@see org.springframework.aop.scope.ScopedProxyFactoryBean
@see org.springframework.web.context.request.RequestScope
@see org.springframework.web.context.request.SessionScope