public class Jsr330ScopeMetadataResolver extends java.lang.Object implements ScopeMetadataResolver
ScopeMetadataResolver
implementation that follows JSR-330 scoping rules:
defaulting to prototype scope unless Singleton
is present.
This scope resolver can be used with ClassPathBeanDefinitionScanner
and
AnnotatedBeanDefinitionReader
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.
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 and Description |
---|
Jsr330ScopeMetadataResolver() |
Modifier and Type | Method and Description |
---|---|
void |
registerScope(java.lang.Class<?> annotationType,
java.lang.String scopeName)
Register an extended JSR-330 scope annotation, mapping it onto a
specific Spring scope by name.
|
void |
registerScope(java.lang.String annotationType,
java.lang.String scopeName)
Register an extended JSR-330 scope annotation, mapping it onto a
specific Spring scope by name.
|
ScopeMetadata |
resolveScopeMetadata(BeanDefinition definition)
Resolve the
ScopeMetadata appropriate to the supplied
bean definition . |
protected java.lang.String |
resolveScopeName(java.lang.String annotationType)
Resolve the given annotation type into a named Spring scope.
|
public final void registerScope(java.lang.Class<?> annotationType, java.lang.String scopeName)
annotationType
- the JSR-330 annotation type as a ClassscopeName
- the Spring scope namepublic final void registerScope(java.lang.String annotationType, java.lang.String scopeName)
annotationType
- the JSR-330 annotation type by namescopeName
- the Spring scope nameprotected java.lang.String resolveScopeName(java.lang.String annotationType)
The default implementation simply checks against registered scopes. Can be overridden for custom mapping rules, e.g. naming conventions.
annotationType
- the JSR-330 annotation typepublic ScopeMetadata resolveScopeMetadata(BeanDefinition definition)
ScopeMetadataResolver
ScopeMetadata
appropriate to the supplied
bean definition
.
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
supplied definition
, or to use metadata present in the
AttributeAccessor.attributeNames()
of the supplied definition
.
resolveScopeMetadata
in interface ScopeMetadataResolver
definition
- the target bean definitionnull