类 AnnotatedBeanDefinitionReader

java.lang.Object
cn.taketoday.beans.factory.config.BeanDefinitionCustomizers
cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader

public class AnnotatedBeanDefinitionReader extends BeanDefinitionCustomizers
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.

从以下版本开始:
4.0
作者:
Juergen Hoeller, Chris Beams, Sam Brannen, Phillip Webb, TODAY 2021/10/1 16:46
  • 构造器详细资料

    • AnnotatedBeanDefinitionReader

      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.

      参数:
      registry - the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
      另请参阅:
    • AnnotatedBeanDefinitionReader

      public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, cn.taketoday.core.env.Environment environment)
      Create a new AnnotatedBeanDefinitionReader for the given registry, 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.
  • 方法详细资料

    • getRegistry

      public final BeanDefinitionRegistry getRegistry()
      Get the BeanDefinitionRegistry that this reader operates on.
    • setEnvironment

      public void setEnvironment(cn.taketoday.core.env.Environment environment)
      Set the Environment 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 the BeanNameGenerator to use for detected bean classes.

      The default is a AnnotationBeanNameGenerator.

    • setScopeMetadataResolver

      public void setScopeMetadataResolver(@Nullable ScopeMetadataResolver scopeMetadataResolver)
      Set the ScopeMetadataResolver 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 bean
      name - an explicit name for the bean (or null for generating a default bean name)
    • 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 bean
      qualifiers - 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 bean
      name - 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 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 bean
      supplier - a callback for creating an instance of the bean (may be null)
    • 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 bean
      name - 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)
    • 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 bean
      name - 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 flag