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

public Class AnnotatedBeanDefinitionReader

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.util.function.Supplier, org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition, org.springframework.beans.factory.config.BeanDefinition, .BeanDefinitionCustomizer, .BeanDefinitionHolder, org.springframework.beans.factory.support.AutowireCandidateQualifier, .BeanDefinitionReaderUtils, .BeanDefinitionRegistry, .BeanNameGenerator, org.springframework.core.env.Environment, .EnvironmentCapable, .StandardEnvironment, org.springframework.lang.Nullable, org.springframework.util.Assert

Convenient adapter for programmatic registration of bean classes.

This is an alternative to ClassPathBeanDefinitionScanner, applying the same resolution of annotations but for explicitly registered classes only.

Authors
Juergen Hoeller, Chris Beams, Sam Brannen, Phillip Webb
Since
3.0
See Also
AnnotationConfigApplicationContext#register

Field Summary

Modifier and TypeField and Description
private BeanNameGenerator
private ConditionEvaluator
private final BeanDefinitionRegistry
private ScopeMetadataResolver

Constructor Summary

AccessConstructor and Description
public
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry
the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
registry
)

Create a new AnnotatedBeanDefinitionReader for the given registry.

public
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry
the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
registry
,
Environment
the Environment to use when evaluating bean definition profiles.
environment
)

Create a new AnnotatedBeanDefinitionReader for the given registry, using the given Environment.

Method Summary

Modifier and TypeMethod and Description
private <T> void
doRegisterBean(Class<T>
the class of the bean
beanClass
,
String
an explicit name for the bean
name
,
Class<? extends Annotation>[]
specific qualifier annotations to consider, if any, in addition to qualifiers at the bean class level
qualifiers
,
Supplier<T>
a callback for creating an instance of the bean (may be null)
supplier
,
BeanDefinitionCustomizer[]
one or more callbacks for customizing the factory's BeanDefinition, e.g. setting a lazy-init or primary flag
customizers
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

private static Environment
getOrCreateEnvironment(BeanDefinitionRegistry registry)

Get the Environment from the given registry if possible, otherwise return a new StandardEnvironment.

public final BeanDefinitionRegistry
getRegistry()

Get the BeanDefinitionRegistry that this reader operates on.

public void
register(Class<?>...
one or more component classes, e.g. @Configuration classes
componentClasses
)

Register one or more component classes to be processed.

public void
registerBean(Class<?>
the class of the bean
beanClass
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

public void
registerBean(Class<?>
the class of the bean
beanClass
,
String
an explicit name for the bean (or null for generating a default bean name)
name
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

public void
registerBean(Class<?>
the class of the bean
beanClass
,
Class<? extends Annotation>...
specific qualifier annotations to consider, in addition to qualifiers at the bean class level
qualifiers
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

public void
registerBean(Class<?>
the class of the bean
beanClass
,
String
an explicit name for the bean (or null for generating a default bean name)
name
,
Class<? extends Annotation>...
specific qualifier annotations to consider, in addition to qualifiers at the bean class level
qualifiers
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

public <T> void
registerBean(Class<T>
the class of the bean
beanClass
,
Supplier<T>
a callback for creating an instance of the bean (may be null)
supplier
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations, using the given supplier for obtaining a new instance (possibly declared as a lambda expression or method reference).

public <T> void
registerBean(Class<T>
the class of the bean
beanClass
,
String
an explicit name for the bean (or null for generating a default bean name)
name
,
Supplier<T>
a callback for creating an instance of the bean (may be null)
supplier
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations, using the given supplier for obtaining a new instance (possibly declared as a lambda expression or method reference).

public <T> void
registerBean(Class<T>
the class of the bean
beanClass
,
String
an explicit name for the bean (or null for generating a default bean name)
name
,
Supplier<T>
a callback for creating an instance of the bean (may be null)
supplier
,
BeanDefinitionCustomizer...
one or more callbacks for customizing the factory's BeanDefinition, e.g. setting a lazy-init or primary flag
customizers
)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

public void
setBeanNameGenerator(BeanNameGenerator beanNameGenerator)

Set the BeanNameGenerator to use for detected bean classes.

public void
setEnvironment(Environment environment)

Set the Environment to use when evaluating whether @Conditional-annotated component classes should be registered.

public void
setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)

Set the ScopeMetadataResolver to use for registered component classes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanNameGeneratorback to summary
private BeanNameGenerator beanNameGenerator
conditionEvaluatorback to summary
private ConditionEvaluator conditionEvaluator
registryback to summary
private final BeanDefinitionRegistry registry
scopeMetadataResolverback to summary
private ScopeMetadataResolver scopeMetadataResolver

Constructor Detail

AnnotatedBeanDefinitionReaderback to summary
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry)

Create a new AnnotatedBeanDefinitionReader for the given registry.

If the registry is EnvironmentCapable, e.g. is an ApplicationContext, the Environment will be inherited, otherwise a new StandardEnvironment will be created and used.

Parameters
registry:BeanDefinitionRegistry

the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry

See Also
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry, Environment), setEnvironment(Environment)
AnnotatedBeanDefinitionReaderback to summary
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment)

Create a new AnnotatedBeanDefinitionReader for the given registry, using the given Environment.

Parameters
registry:BeanDefinitionRegistry

the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry

environment:Environment

the Environment to use when evaluating bean definition profiles.

Since
3.1

Method Detail

doRegisterBeanback to summary
private <T> void doRegisterBean(Class<T> beanClass, String name, Class<? extends Annotation>[] qualifiers, Supplier<T> supplier, BeanDefinitionCustomizer[] customizers)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

Parameters
beanClass:Class<T>

the class of the bean

name:String

an explicit name for the bean

qualifiers:Class<? extends Annotation>[]

specific qualifier annotations to consider, if any, in addition to qualifiers at the bean class level

supplier:Supplier<T>

a callback for creating an instance of the bean (may be null)

customizers:BeanDefinitionCustomizer[]

one or more callbacks for customizing the factory's BeanDefinition, e.g. setting a lazy-init or primary flag

Since
5.0
getOrCreateEnvironmentback to summary
private static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry)

Get the Environment from the given registry if possible, otherwise return a new StandardEnvironment.

getRegistryback to summary
public final BeanDefinitionRegistry getRegistry()

Get the BeanDefinitionRegistry that this reader operates on.

registerback to summary
public void register(Class<?>... componentClasses)

Register one or more component classes to be processed.

Calls to register are idempotent; adding the same component class more than once has no additional effect.

Parameters
componentClasses:Class<?>[]

one or more component classes, e.g. @Configuration classes

registerBeanback to summary
public void registerBean(Class<?> beanClass)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

Parameters
beanClass:Class<?>

the class of the bean

registerBeanback to summary
public void registerBean(Class<?> beanClass, String name)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

Parameters
beanClass:Class<?>

the class of the bean

name:String

an explicit name for the bean (or null for generating a default bean name)

Since
5.2
registerBeanback to summary
public void registerBean(Class<?> beanClass, Class<? extends Annotation>... qualifiers)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

Parameters
beanClass:Class<?>

the class of the bean

qualifiers:Class<? extends Annotation>[]

specific qualifier annotations to consider, in addition to qualifiers at the bean class level

Annotations
@SuppressWarnings:unchecked
registerBeanback to summary
public void registerBean(Class<?> beanClass, String name, Class<? extends Annotation>... qualifiers)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

Parameters
beanClass:Class<?>

the class of the bean

name:String

an explicit name for the bean (or null for generating a default bean name)

qualifiers:Class<? extends Annotation>[]

specific qualifier annotations to consider, in addition to qualifiers at the bean class level

Annotations
@SuppressWarnings:unchecked
registerBeanback to summary
public <T> void registerBean(Class<T> beanClass, Supplier<T> supplier)

Register a bean from the given bean class, deriving its metadata from class-declared annotations, using the given supplier for obtaining a new instance (possibly declared as a lambda expression or method reference).

Parameters
beanClass:Class<T>

the class of the bean

supplier:Supplier<T>

a callback for creating an instance of the bean (may be null)

Since
5.0
registerBeanback to summary
public <T> void registerBean(Class<T> beanClass, String name, Supplier<T> supplier)

Register a bean from the given bean class, deriving its metadata from class-declared annotations, using the given supplier for obtaining a new instance (possibly declared as a lambda expression or method reference).

Parameters
beanClass:Class<T>

the class of the bean

name:String

an explicit name for the bean (or null for generating a default bean name)

supplier:Supplier<T>

a callback for creating an instance of the bean (may be null)

Since
5.0
registerBeanback to summary
public <T> void registerBean(Class<T> beanClass, String name, Supplier<T> supplier, BeanDefinitionCustomizer... customizers)

Register a bean from the given bean class, deriving its metadata from class-declared annotations.

Parameters
beanClass:Class<T>

the class of the bean

name:String

an explicit name for the bean (or null for generating a default bean name)

supplier:Supplier<T>

a callback for creating an instance of the bean (may be null)

customizers:BeanDefinitionCustomizer[]

one or more callbacks for customizing the factory's BeanDefinition, e.g. setting a lazy-init or primary flag

Since
5.2
setBeanNameGeneratorback to summary
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator)

Set the BeanNameGenerator to use for detected bean classes.

The default is a AnnotationBeanNameGenerator.

setEnvironmentback to summary
public void setEnvironment(Environment environment)

Set the Environment to use when evaluating whether @Conditional-annotated component classes should be registered.

The default is a StandardEnvironment.

See Also
registerBean(Class, String, Class...)
setScopeMetadataResolverback to summary
public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)

Set the ScopeMetadataResolver to use for registered component classes.

The default is an AnnotationScopeMetadataResolver.