Class AnnotatedBeanDefinitionReader
java.lang.Object
org.springframework.context.annotation.AnnotatedBeanDefinitionReader
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.
- Since:
- 3.0
- Author:
- Juergen Hoeller, Chris Beams, Sam Brannen, Phillip Webb, Yanming Zhou
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate a newAnnotatedBeanDefinitionReader
for the given registry.AnnotatedBeanDefinitionReader
(BeanDefinitionRegistry registry, Environment environment) Create a newAnnotatedBeanDefinitionReader
for the given registry, using the givenEnvironment
. -
Method Summary
Modifier and TypeMethodDescriptionfinal BeanDefinitionRegistry
Get the BeanDefinitionRegistry that this reader operates on.void
Register one or more component classes to be processed.void
registerBean
(Class<?> beanClass) Register a bean from the given bean class, deriving its metadata from class-declared annotations.void
registerBean
(Class<?> beanClass, Class<? extends Annotation>... qualifiers) Register a bean from the given bean class, deriving its metadata from class-declared annotations.void
registerBean
(Class<?> beanClass, String name) Register a bean from the given bean class, deriving its metadata from class-declared annotations.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.<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).<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.<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).void
setBeanNameGenerator
(BeanNameGenerator beanNameGenerator) Set theBeanNameGenerator
to use for detected bean classes.void
setEnvironment
(Environment environment) Set theEnvironment
to use when evaluating whether@Conditional
-annotated component classes should be registered.void
setScopeMetadataResolver
(ScopeMetadataResolver scopeMetadataResolver) Set theScopeMetadataResolver
to use for registered component classes.
-
Constructor Details
-
AnnotatedBeanDefinitionReader
Create a newAnnotatedBeanDefinitionReader
for the given registry.If the registry is
EnvironmentCapable
, for example, is anApplicationContext
, theEnvironment
will be inherited, otherwise a newStandardEnvironment
will be created and used.- Parameters:
registry
- theBeanFactory
to load bean definitions into, in the form of aBeanDefinitionRegistry
- See Also:
-
AnnotatedBeanDefinitionReader
Create a newAnnotatedBeanDefinitionReader
for the given registry, using the givenEnvironment
.- Parameters:
registry
- theBeanFactory
to load bean definitions into, in the form of aBeanDefinitionRegistry
environment
- theEnvironment
to use when evaluating bean definition profiles.- Since:
- 3.1
-
-
Method Details
-
getRegistry
Get the BeanDefinitionRegistry that this reader operates on. -
setEnvironment
Set theEnvironment
to use when evaluating whether@Conditional
-annotated component classes should be registered.The default is a
StandardEnvironment
. -
setBeanNameGenerator
Set theBeanNameGenerator
to use for detected bean classes.The default is a
AnnotationBeanNameGenerator
. -
setScopeMetadataResolver
Set theScopeMetadataResolver
to use for registered component classes.The default is an
AnnotationScopeMetadataResolver
. -
register
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
- one or more component classes, for example,@Configuration
classes
-
registerBean
Register a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
beanClass
- the class of the bean
-
registerBean
Register a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
beanClass
- the class of the beanname
- an explicit name for the bean (ornull
for generating a default bean name)- Since:
- 5.2
-
registerBean
Register a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
beanClass
- the class of the beanqualifiers
- specific qualifier annotations to consider, in addition to qualifiers at the bean class level
-
registerBean
public void registerBean(Class<?> beanClass, @Nullable String name, Class<? extends Annotation>... qualifiers) Register a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
beanClass
- the class of the beanname
- an explicit name for the bean (ornull
for generating a default bean name)qualifiers
- specific qualifier annotations to consider, in addition to qualifiers at the bean class level
-
registerBean
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
- the class of the beansupplier
- a callback for creating an instance of the bean (may benull
)- Since:
- 5.0
-
registerBean
public <T> void registerBean(Class<T> beanClass, @Nullable String name, @Nullable 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
- the class of the beanname
- an explicit name for the bean (ornull
for generating a default bean name)supplier
- a callback for creating an instance of the bean (may benull
)- Since:
- 5.0
-
registerBean
public <T> void registerBean(Class<T> beanClass, @Nullable String name, @Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) Register a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
beanClass
- the class of the beanname
- an explicit name for the bean (ornull
for generating a default bean name)supplier
- a callback for creating an instance of the bean (may benull
)customizers
- one or more callbacks for customizing the factory'sBeanDefinition
, for example, setting a lazy-init or primary flag- Since:
- 5.2
-