org.springframework.context.annotation
Class AnnotatedBeanDefinitionReader

java.lang.Object
  extended by org.springframework.context.annotation.AnnotatedBeanDefinitionReader

public class AnnotatedBeanDefinitionReader
extends java.lang.Object

Convenient adapter for programmatic registration of annotated 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
See Also:
AnnotationConfigApplicationContext.register(java.lang.Class...)

Field Summary
private  BeanNameGenerator beanNameGenerator
           
private  Environment environment
           
private  BeanDefinitionRegistry registry
           
private  ScopeMetadataResolver scopeMetadataResolver
           
 
Constructor Summary
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.
 
Method Summary
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)
           
 void registerBean(java.lang.Class<?> annotatedClass)
           
 void registerBean(java.lang.Class<?> annotatedClass, java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)
           
 void registerBean(java.lang.Class<?> annotatedClass, java.lang.String name, java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)
           
 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 @Profile-annotated component classes should be registered.
 void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)
          Set the ScopeMetadataResolver to use for detected bean classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registry

private final BeanDefinitionRegistry registry

environment

private Environment environment

beanNameGenerator

private BeanNameGenerator beanNameGenerator

scopeMetadataResolver

private ScopeMetadataResolver scopeMetadataResolver
Constructor Detail

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.

Parameters:
registry - the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
See Also:
AnnotatedBeanDefinitionReader(BeanDefinitionRegistry, Environment), setEnvironment(Environment)

AnnotatedBeanDefinitionReader

public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry,
                                     Environment environment)
Create a new AnnotatedBeanDefinitionReader for the given registry and using the given Environment.

Parameters:
registry - the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry
environment - the Environment to use when evaluating bean definition profiles.
Since:
3.1
Method Detail

getRegistry

public final BeanDefinitionRegistry getRegistry()
Return the BeanDefinitionRegistry that this scanner operates on.


setEnvironment

public void setEnvironment(Environment environment)
Set the Environment to use when evaluating whether @Profile-annotated component classes should be registered.

The default is a StandardEnvironment.

See Also:
registerBean(Class, String, Class...)

setBeanNameGenerator

public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
Set the BeanNameGenerator to use for detected bean classes.

The default is a AnnotationBeanNameGenerator.


setScopeMetadataResolver

public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)
Set the ScopeMetadataResolver to use for detected bean classes.

The default is an AnnotationScopeMetadataResolver.


register

public void register(java.lang.Class<?>... annotatedClasses)

registerBean

public void registerBean(java.lang.Class<?> annotatedClass)

registerBean

public void registerBean(java.lang.Class<?> annotatedClass,
                         java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)

registerBean

public void registerBean(java.lang.Class<?> annotatedClass,
                         java.lang.String name,
                         java.lang.Class<? extends java.lang.annotation.Annotation>... qualifiers)

getOrCreateEnvironment

private static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry)
Get the Environment from the given registry if possible, otherwise return a new StandardEnvironment.