Annotation Type Scope
@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented public @interface Scope
When used as a type-level annotation in conjunction with@Component,@Scopeindicates the name of a scope to use for instances of the annotated type.When used as a method-level annotation in conjunction with
@Bean,@Scopeindicates the name of a scope to use for the instance returned from the method.NOTE:
@Scopeannotations are only introspected on the concrete bean class (for annotated components) or the factory method (for@Beanmethods). In contrast to XML bean definitions, there is no notion of bean definition inheritance, and inheritance hierarchies at the class level are irrelevant for metadata purposes.In this context, scope means the lifecycle of an instance, such as
singleton,prototype, and so forth. Scopes provided out of the box in Spring may be referred to using theSCOPE_*constants available in theConfigurableBeanFactoryandWebApplicationContextinterfaces.To register additional custom scopes, see
CustomScopeConfigurer.
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description ScopedProxyModeproxyModeSpecifies whether a component should be configured as a scoped proxy and if so, whether the proxy should be interface-based or subclass-based.StringscopeNameSpecifies the name of the scope to use for the annotated component/bean.StringvalueAlias forscopeName().
Element Detail
value
@AliasFor("scopeName") String value
Alias forscopeName().- See Also:
scopeName()
- Default:
- ""
scopeName
@AliasFor("value") String scopeName
Specifies the name of the scope to use for the annotated component/bean.Defaults to an empty string (
"") which impliesSCOPE_SINGLETON.- Since:
- 4.2
- See Also:
ConfigurableBeanFactory.SCOPE_PROTOTYPE,ConfigurableBeanFactory.SCOPE_SINGLETON,WebApplicationContext.SCOPE_REQUEST,WebApplicationContext.SCOPE_SESSION,value()
- Default:
- ""
proxyMode
ScopedProxyMode proxyMode
Specifies whether a component should be configured as a scoped proxy and if so, whether the proxy should be interface-based or subclass-based.Defaults to
ScopedProxyMode.DEFAULT, which typically indicates that no scoped proxy should be created unless a different default has been configured at the component-scan instruction level.Analogous to
<aop:scoped-proxy/>support in Spring XML.- See Also:
ScopedProxyMode
- Default:
- org.springframework.context.annotation.ScopedProxyMode.DEFAULT