Top Description Fields Constructors Methods
org.springframework.context.annotation

public Class Jsr330ScopeMetadataResolver

extends Object
implements ScopeMetadataResolver
Class Inheritance
All Implemented Interfaces
org.springframework.context.annotation.ScopeMetadataResolver
Imports
java.util.HashMap, .Map, .Set, org.springframework.beans.factory.annotation.AnnotatedBeanDefinition, org.springframework.beans.factory.config.BeanDefinition, org.springframework.lang.Nullable

Simple ScopeMetadataResolver implementation that follows JSR-330 scoping rules: defaulting to prototype scope unless jakarta.inject.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.

Author
Juergen Hoeller
Since
3.0
See Also
registerScope, resolveScopeName, ClassPathBeanDefinitionScanner#setScopeMetadataResolver, AnnotatedBeanDefinitionReader#setScopeMetadataResolver

Field Summary

Modifier and TypeField and Description
private final Map<String, String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
registerScope(Class<?>
the JSR-330 annotation type as a Class
annotationType
,
String
the Spring scope name
scopeName
)

Register an extended JSR-330 scope annotation, mapping it onto a specific Spring scope by name.

public final void
registerScope(String
the JSR-330 annotation type by name
annotationType
,
String
the Spring scope name
scopeName
)

Register an extended JSR-330 scope annotation, mapping it onto a specific Spring scope by name.

public ScopeMetadata
resolveScopeMetadata(BeanDefinition
the target bean definition
definition
)

Implements org.springframework.context.annotation.ScopeMetadataResolver.resolveScopeMetadata.

Resolve the ScopeMetadata appropriate to the supplied bean definition.

protected String

Returns:

the Spring scope name
resolveScopeName
(String
the JSR-330 annotation type
annotationType
)

Resolve the given annotation type into a named Spring scope.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

scopeMapback to summary
private final Map<String, String> scopeMap

Constructor Detail

Jsr330ScopeMetadataResolverback to summary
public Jsr330ScopeMetadataResolver()

Method Detail

registerScopeback to summary
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:Class<?>

the JSR-330 annotation type as a Class

scopeName:String

the Spring scope name

registerScopeback to summary
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:String

the JSR-330 annotation type by name

scopeName:String

the Spring scope name

resolveScopeMetadataback to summary
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition)

Implements org.springframework.context.annotation.ScopeMetadataResolver.resolveScopeMetadata.

Doc from org.springframework.context.annotation.ScopeMetadataResolver.resolveScopeMetadata.

Resolve the 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 BeanDefinition#attributeNames() of the supplied definition.

Parameters
definition:BeanDefinition

the target bean definition

Returns:ScopeMetadata

the relevant scope metadata; never null

Annotations
@Override
resolveScopeNameback to summary
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:String

the JSR-330 annotation type

Returns:String

the Spring scope name

Annotations
@Nullable