public class AnnotatedBeanDefinitionReader
extends java.lang.Object
ClassPathBeanDefinitionScanner
, applying
the same resolution of annotations but for explicitly registered classes only.AnnotationConfigApplicationContext.register(java.lang.Class<?>...)
Modifier and Type | Field and Description |
---|---|
private BeanNameGenerator |
beanNameGenerator |
private ConditionEvaluator |
conditionEvaluator |
private BeanDefinitionRegistry |
registry |
private ScopeMetadataResolver |
scopeMetadataResolver |
Constructor and Description |
---|
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry)
Create a new
AnnotatedBeanDefinitionReader for the given registry. |
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry,
Environment environment)
Create a new
AnnotatedBeanDefinitionReader for the given registry and using
the given Environment . |
Modifier and Type | Method and Description |
---|---|
private <T> void |
doRegisterBean(java.lang.Class<T> annotatedClass,
java.lang.String name,
java.lang.Class<? extends java.lang.annotation.Annotation>[] qualifiers,
java.util.function.Supplier<T> supplier,
BeanDefinitionCustomizer[] 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.
|
BeanDefinitionRegistry |
getRegistry()
Return the BeanDefinitionRegistry that this scanner operates on.
|
void |
register(java.lang.Class<?>... annotatedClasses)
Register one or more annotated classes to be processed.
|
void |
registerBean(java.lang.Class<?> annotatedClass)
Register a bean from the given bean class, deriving its metadata from
class-declared annotations.
|
void |
registerBean(java.lang.Class<?> annotatedClass,
java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)
Register a bean from the given bean class, deriving its metadata from
class-declared annotations.
|
void |
registerBean(java.lang.Class<?> annotatedClass,
java.lang.String name)
Register a bean from the given bean class, deriving its metadata from
class-declared annotations.
|
void |
registerBean(java.lang.Class<?> annotatedClass,
java.lang.String name,
java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)
Register a bean from the given bean class, deriving its metadata from
class-declared annotations.
|
<T> void |
registerBean(java.lang.Class<T> annotatedClass,
java.lang.String name,
java.util.function.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(java.lang.Class<T> annotatedClass,
java.lang.String name,
java.util.function.Supplier<T> supplier,
BeanDefinitionCustomizer... customizers)
Register a bean from the given bean class, deriving its metadata from
class-declared annotations.
|
<T> void |
registerBean(java.lang.Class<T> annotatedClass,
java.util.function.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 the BeanNameGenerator to use for detected bean classes.
|
void |
setEnvironment(Environment environment)
Set the Environment to use when evaluating whether
@Conditional -annotated component classes should be registered. |
void |
setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)
Set the ScopeMetadataResolver to use for detected bean classes.
|
private final BeanDefinitionRegistry registry
private BeanNameGenerator beanNameGenerator
private ScopeMetadataResolver scopeMetadataResolver
private ConditionEvaluator conditionEvaluator
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry)
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.registry
- the BeanFactory
to load bean definitions into,
in the form of a BeanDefinitionRegistry
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry, Environment)
,
setEnvironment(Environment)
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment)
AnnotatedBeanDefinitionReader
for the given registry and using
the given Environment
.registry
- the BeanFactory
to load bean definitions into,
in the form of a BeanDefinitionRegistry
environment
- the Environment
to use when evaluating bean definition
profiles.public final BeanDefinitionRegistry getRegistry()
public void setEnvironment(Environment environment)
@Conditional
-annotated component classes should be registered.
The default is a StandardEnvironment
.
registerBean(Class, String, Class...)
public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator)
The default is a AnnotationBeanNameGenerator
.
public void setScopeMetadataResolver(@Nullable ScopeMetadataResolver scopeMetadataResolver)
The default is an AnnotationScopeMetadataResolver
.
public void register(java.lang.Class<?>... annotatedClasses)
Calls to register
are idempotent; adding the same
annotated class more than once has no additional effect.
annotatedClasses
- one or more annotated classes,
e.g. @Configuration
classespublic void registerBean(java.lang.Class<?> annotatedClass)
annotatedClass
- the class of the beanpublic void registerBean(java.lang.Class<?> annotatedClass, @Nullable java.lang.String name)
annotatedClass
- the class of the beanname
- an explicit name for the bean
(or null
for generating a default bean name)public void registerBean(java.lang.Class<?> annotatedClass, java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)
annotatedClass
- the class of the beanqualifiers
- specific qualifier annotations to consider,
in addition to qualifiers at the bean class levelpublic void registerBean(java.lang.Class<?> annotatedClass, @Nullable java.lang.String name, java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)
annotatedClass
- the class of the beanname
- an explicit name for the bean
(or null
for generating a default bean name)qualifiers
- specific qualifier annotations to consider,
in addition to qualifiers at the bean class levelpublic <T> void registerBean(java.lang.Class<T> annotatedClass, @Nullable java.util.function.Supplier<T> supplier)
annotatedClass
- the class of the beansupplier
- a callback for creating an instance of the bean
(may be null
)public <T> void registerBean(java.lang.Class<T> annotatedClass, @Nullable java.lang.String name, @Nullable java.util.function.Supplier<T> supplier)
annotatedClass
- the class of the beanname
- an explicit name for the bean
(or null
for generating a default bean name)supplier
- a callback for creating an instance of the bean
(may be null
)public <T> void registerBean(java.lang.Class<T> annotatedClass, @Nullable java.lang.String name, @Nullable java.util.function.Supplier<T> supplier, BeanDefinitionCustomizer... customizers)
annotatedClass
- the class of the beanname
- an explicit name for the bean
(or null
for generating a default bean name)supplier
- a callback for creating an instance of the bean
(may be null
)customizers
- one or more callbacks for customizing the factory's
BeanDefinition
, e.g. setting a lazy-init or primary flagprivate <T> void doRegisterBean(java.lang.Class<T> annotatedClass, @Nullable java.lang.String name, @Nullable java.lang.Class<? extends java.lang.annotation.Annotation>[] qualifiers, @Nullable java.util.function.Supplier<T> supplier, @Nullable BeanDefinitionCustomizer[] customizers)
annotatedClass
- the class of the beanname
- an explicit name for the beansupplier
- a callback for creating an instance of the bean
(may be null
)qualifiers
- specific qualifier annotations to consider, if any,
in addition to qualifiers at the bean class levelcustomizers
- one or more callbacks for customizing the factory's
BeanDefinition
, e.g. setting a lazy-init or primary flagprivate static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry)