@Configuration-annotated classes, but also plain
@Component types and JSR-330 compliant
classes using jakarta.inject annotations.
Allows for registering classes one by one using register(Class.
as well as for classpath scanning using scan(String..
In case of multiple @Configuration classes, @Bean methods
defined in later classes will override those defined in earlier classes. This can
be leveraged to deliberately override certain bean definitions via an extra
@Configuration class.
See @Configuration's javadoc for usage examples.
register, scan, AnnotatedBeanDefinitionReader, ClassPathBeanDefinitionScanner, org.springframework.context.support.GenericXmlApplicationContext
| Modifier and Type | Field and Description |
|---|---|
| private final AnnotatedBeanDefinitionReader | |
| private final ClassPathBeanDefinitionScanner |
| Access | Constructor and Description |
|---|---|
| public | AnnotationConfigApplicationContext()
Create a new AnnotationConfigApplicationContext that needs to be populated
through |
| public | AnnotationConfigApplicationContext(DefaultListableBeanFactory
the DefaultListableBeanFactory instance to use for this context beanFactory)Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory. |
| public | AnnotationConfigApplicationContext(Class<?>...
one or more component classes — for example,
componentClasses)@Configuration classesCreate a new AnnotationConfigApplicationContext, deriving bean definitions from the given component classes and automatically refreshing the context. |
| public | AnnotationConfigApplicationContext(String...
the packages to scan for component classes basePackages)Create a new AnnotationConfigApplicationContext, scanning for components in the given packages, registering bean definitions for those components, and automatically refreshing the context. |
| Modifier and Type | Method and Description |
|---|---|
| public void | register(Class<?>...
one or more component classes — for example,
componentClasses)@Configuration classesImplements org. Register one or more component classes to be processed. |
| public <T> void | registerBean(String
the name of the bean (may be beanName, Class<T> null)the class of the bean beanClass, Supplier<T> a callback for creating an instance of the bean (in case
of supplier, BeanDefinitionCustomizer... null, resolving a public constructor to be autowired instead)one or more callbacks for customizing the factory's
customizers)BeanDefinition, e.g. setting a lazy-init or primary flagOverrides org. Register a bean from the given bean class, using the given supplier for obtaining a new instance (typically declared as a lambda expression or method reference), optionally customizing its bean definition metadata (again typically declared as a lambda expression). |
| public void | scan(String...
the packages to scan for component classes basePackages)Implements org. Perform a scan within the specified base packages. |
| public void | setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
Provide a custom |
| public void | setEnvironment(ConfigurableEnvironment
the new environment environment)Overrides org. Implements org. Propagate the given custom |
| public void | setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)
Set the |
| reader | back to summary |
|---|---|
| private final AnnotatedBeanDefinitionReader reader | |
| scanner | back to summary |
|---|---|
| private final ClassPathBeanDefinitionScanner scanner | |
| AnnotationConfigApplicationContext | back to summary |
|---|---|
| public AnnotationConfigApplicationContext() Create a new AnnotationConfigApplicationContext that needs to be populated
through | |
| AnnotationConfigApplicationContext | back to summary |
|---|---|
| public AnnotationConfigApplicationContext(DefaultListableBeanFactory beanFactory) Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory.
| |
| AnnotationConfigApplicationContext | back to summary |
|---|---|
| public AnnotationConfigApplicationContext(Class<?>... componentClasses) Create a new AnnotationConfigApplicationContext, deriving bean definitions from the given component classes and automatically refreshing the context.
| |
| AnnotationConfigApplicationContext | back to summary |
|---|---|
| public AnnotationConfigApplicationContext(String... basePackages) Create a new AnnotationConfigApplicationContext, scanning for components in the given packages, registering bean definitions for those components, and automatically refreshing the context.
| |
| register | back to summary |
|---|---|
| public void register(Class<?>... componentClasses) Implements org. Register one or more component classes to be processed. Note that
| |
| registerBean | back to summary |
|---|---|
| public <T> void registerBean(String beanName, Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) Overrides org. Doc from org. Register a bean from the given bean class, using the given supplier for obtaining a new instance (typically declared as a lambda expression or method reference), optionally customizing its bean definition metadata (again typically declared as a lambda expression). This method can be overridden to adapt the registration mechanism for
all
| |
| scan | back to summary |
|---|---|
| public void scan(String... basePackages) Implements org. Perform a scan within the specified base packages. Note that
| |
| setBeanNameGenerator | back to summary |
|---|---|
| public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) Provide a custom Default is Any call to this method must occur prior to calls to | |
| setEnvironment | back to summary |
|---|---|
| public void setEnvironment(ConfigurableEnvironment environment) Overrides org. Implements org. Propagate the given custom
| |
| setScopeMetadataResolver | back to summary |
|---|---|
| public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver) Set the The default is an Any call to this method must occur prior to calls to | |