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 SummaryConstructorsConstructorDescriptionCreate a newAnnotatedBeanDefinitionReaderfor the given registry.AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment) Create a newAnnotatedBeanDefinitionReaderfor the given registry, using the givenEnvironment.
- 
Method SummaryModifier and TypeMethodDescriptionfinal BeanDefinitionRegistryGet the BeanDefinitionRegistry that this reader operates on.voidRegister one or more component classes to be processed.voidregisterBean(Class<?> beanClass) Register a bean from the given bean class, deriving its metadata from class-declared annotations.voidregisterBean(Class<?> beanClass, Class<? extends Annotation>... qualifiers) Register a bean from the given bean class, deriving its metadata from class-declared annotations.voidregisterBean(Class<?> beanClass, String name) Register a bean from the given bean class, deriving its metadata from class-declared annotations.voidregisterBean(Class<?> beanClass, String name, Class<? extends Annotation>... qualifiers) Register a bean from the given bean class, deriving its metadata from class-declared annotations.<T> voidregisterBean(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> voidregisterBean(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> voidregisterBean(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).voidsetBeanNameGenerator(BeanNameGenerator beanNameGenerator) Set theBeanNameGeneratorto use for detected bean classes.voidsetEnvironment(Environment environment) Set theEnvironmentto use when evaluating whether@Conditional-annotated component classes should be registered.voidsetScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver) Set theScopeMetadataResolverto use for registered component classes.
- 
Constructor Details- 
AnnotatedBeanDefinitionReaderCreate a newAnnotatedBeanDefinitionReaderfor the given registry.If the registry is EnvironmentCapable, for example, is anApplicationContext, theEnvironmentwill be inherited, otherwise a newStandardEnvironmentwill be created and used.- Parameters:
- registry- the- BeanFactoryto load bean definitions into, in the form of a- BeanDefinitionRegistry
- See Also:
 
- 
AnnotatedBeanDefinitionReaderCreate a newAnnotatedBeanDefinitionReaderfor the given registry, using the givenEnvironment.- Parameters:
- registry- the- BeanFactoryto load bean definitions into, in the form of a- BeanDefinitionRegistry
- environment- the- Environmentto use when evaluating bean definition profiles.
- Since:
- 3.1
 
 
- 
- 
Method Details- 
getRegistryGet the BeanDefinitionRegistry that this reader operates on.
- 
setEnvironmentSet theEnvironmentto use when evaluating whether@Conditional-annotated component classes should be registered.The default is a StandardEnvironment.
- 
setBeanNameGeneratorSet theBeanNameGeneratorto use for detected bean classes.The default is a AnnotationBeanNameGenerator.
- 
setScopeMetadataResolverSet theScopeMetadataResolverto use for registered component classes.The default is an AnnotationScopeMetadataResolver.
- 
registerRegister one or more component classes to be processed.Calls to registerare idempotent; adding the same component class more than once has no additional effect.- Parameters:
- componentClasses- one or more component classes, for example,- @Configurationclasses
 
- 
registerBeanRegister a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
- beanClass- the class of the bean
 
- 
registerBeanRegister a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
- beanClass- the class of the bean
- name- an explicit name for the bean (or- nullfor generating a default bean name)
- Since:
- 5.2
 
- 
registerBeanRegister a bean from the given bean class, deriving its metadata from class-declared annotations.- Parameters:
- beanClass- the class of the bean
- qualifiers- specific qualifier annotations to consider, in addition to qualifiers at the bean class level
 
- 
registerBeanpublic 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 bean
- name- an explicit name for the bean (or- nullfor generating a default bean name)
- qualifiers- specific qualifier annotations to consider, in addition to qualifiers at the bean class level
 
- 
registerBeanRegister 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 bean
- supplier- a callback for creating an instance of the bean (may be- null)
- Since:
- 5.0
 
- 
registerBeanpublic <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 bean
- name- an explicit name for the bean (or- nullfor generating a default bean name)
- supplier- a callback for creating an instance of the bean (may be- null)
- Since:
- 5.0
 
- 
registerBeanpublic <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 bean
- name- an explicit name for the bean (or- nullfor 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, for example, setting a lazy-init or primary flag
- Since:
- 5.2
 
 
-