类 AnnotatedBeanDefinitionReader
- java.lang.Object
- org.springframework.context.annotation.AnnotatedBeanDefinitionReader
public class AnnotatedBeanDefinitionReader extends Object
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.- 从以下版本开始:
- 3.0
- 作者:
- Juergen Hoeller, Chris Beams, Sam Brannen, Phillip Webb
- 另请参阅:
AnnotationConfigApplicationContext.register(java.lang.Class<?>...)
构造器概要
构造器 构造器 说明 AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry)
Create a newAnnotatedBeanDefinitionReader
for the given registry.AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment)
Create a newAnnotatedBeanDefinitionReader
for the given registry, using the givenEnvironment
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 BeanDefinitionRegistry
getRegistry()
Get the BeanDefinitionRegistry that this reader operates on.void
register(Class<?>... componentClasses)
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.
构造器详细资料
AnnotatedBeanDefinitionReader
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry)
Create a newAnnotatedBeanDefinitionReader
for the given registry.If the registry is
EnvironmentCapable
, e.g. is anApplicationContext
, theEnvironment
will be inherited, otherwise a newStandardEnvironment
will be created and used.- 参数:
registry
- theBeanFactory
to load bean definitions into, in the form of aBeanDefinitionRegistry
- 另请参阅:
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry, Environment)
,setEnvironment(Environment)
AnnotatedBeanDefinitionReader
public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment)
Create a newAnnotatedBeanDefinitionReader
for the given registry, using the givenEnvironment
.- 参数:
registry
- theBeanFactory
to load bean definitions into, in the form of aBeanDefinitionRegistry
environment
- theEnvironment
to use when evaluating bean definition profiles.- 从以下版本开始:
- 3.1
方法详细资料
getRegistry
public final BeanDefinitionRegistry getRegistry()
Get the BeanDefinitionRegistry that this reader operates on.
setEnvironment
public void setEnvironment(Environment environment)
Set theEnvironment
to use when evaluating whether@Conditional
-annotated component classes should be registered.The default is a
StandardEnvironment
.
setBeanNameGenerator
public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator)
Set theBeanNameGenerator
to use for detected bean classes.The default is a
AnnotationBeanNameGenerator
.
setScopeMetadataResolver
public void setScopeMetadataResolver(@Nullable ScopeMetadataResolver scopeMetadataResolver)
Set theScopeMetadataResolver
to use for registered component classes.The default is an
AnnotationScopeMetadataResolver
.
register
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.- 参数:
componentClasses
- one or more component classes, e.g.@Configuration
classes
registerBean
public void registerBean(Class<?> beanClass)
Register a bean from the given bean class, deriving its metadata from class-declared annotations.- 参数:
beanClass
- the class of the bean
registerBean
public void registerBean(Class<?> beanClass, @Nullable String name)
Register a bean from the given bean class, deriving its metadata from class-declared annotations.- 参数:
beanClass
- the class of the beanname
- an explicit name for the bean (ornull
for generating a default bean name)- 从以下版本开始:
- 5.2
registerBean
public void registerBean(Class<?> beanClass, Class<? extends Annotation>... qualifiers)
Register a bean from the given bean class, deriving its metadata from class-declared annotations.- 参数:
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.- 参数:
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
public <T> void registerBean(Class<T> beanClass, @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).- 参数:
beanClass
- the class of the beansupplier
- a callback for creating an instance of the bean (may benull
)- 从以下版本开始:
- 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).- 参数:
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
)- 从以下版本开始:
- 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.- 参数:
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
, e.g. setting a lazy-init or primary flag- 从以下版本开始:
- 5.2