Class Jsr330ScopeMetadataResolver
- java.lang.Object
- org.springframework.context.annotation.Jsr330ScopeMetadataResolver
- All Implemented Interfaces:
ScopeMetadataResolver
public class Jsr330ScopeMetadataResolver extends Object implements ScopeMetadataResolver
SimpleScopeMetadataResolver
implementation that follows JSR-330 scoping rules: defaulting to prototype scope unlessSingleton
is present.This scope resolver can be used with
ClassPathBeanDefinitionScanner
andAnnotatedBeanDefinitionReader
for standard JSR-330 compliance. However, in practice, you will typically use Spring's rich default scoping instead - or extend this resolver with custom scoping annotations that point to extended Spring scopes.- Since:
- 3.0
- Author:
- Juergen Hoeller
- See Also:
registerScope(java.lang.Class<?>, java.lang.String)
,resolveScopeName(java.lang.String)
,ClassPathBeanDefinitionScanner.setScopeMetadataResolver(org.springframework.context.annotation.ScopeMetadataResolver)
,AnnotatedBeanDefinitionReader.setScopeMetadataResolver(org.springframework.context.annotation.ScopeMetadataResolver)
Constructor Summary
Constructors Constructor Description Jsr330ScopeMetadataResolver()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
registerScope(Class<?> annotationType, String scopeName)
Register an extended JSR-330 scope annotation, mapping it onto a specific Spring scope by name.void
registerScope(String annotationType, String scopeName)
Register an extended JSR-330 scope annotation, mapping it onto a specific Spring scope by name.ScopeMetadata
resolveScopeMetadata(BeanDefinition definition)
Resolve theScopeMetadata
appropriate to the supplied beandefinition
.protected String
resolveScopeName(String annotationType)
Resolve the given annotation type into a named Spring scope.
Constructor Detail
Jsr330ScopeMetadataResolver
public Jsr330ScopeMetadataResolver()
Method Detail
registerScope
public final void registerScope(Class<?> annotationType, String scopeName)
Register an extended JSR-330 scope annotation, mapping it onto a specific Spring scope by name.- Parameters:
annotationType
- the JSR-330 annotation type as a ClassscopeName
- the Spring scope name
registerScope
public final void registerScope(String annotationType, String scopeName)
Register an extended JSR-330 scope annotation, mapping it onto a specific Spring scope by name.- Parameters:
annotationType
- the JSR-330 annotation type by namescopeName
- the Spring scope name
resolveScopeName
@Nullable protected String resolveScopeName(String annotationType)
Resolve the given annotation type into a named Spring scope.The default implementation simply checks against registered scopes. Can be overridden for custom mapping rules, e.g. naming conventions.
- Parameters:
annotationType
- the JSR-330 annotation type- Returns:
- the Spring scope name
resolveScopeMetadata
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition)
Description copied from interface:ScopeMetadataResolver
Resolve theScopeMetadata
appropriate to the supplied beandefinition
.Implementations can of course use any strategy they like to determine the scope metadata, but some implementations that spring immediately to mind might be to use source level annotations present on
the class
of the supplieddefinition
, or to use metadata present in theAttributeAccessor.attributeNames()
of the supplieddefinition
.- Specified by:
resolveScopeMetadata
in interfaceScopeMetadataResolver
- Parameters:
definition
- the target bean definition- Returns:
- the relevant scope metadata; never
null