Class AnnotationConfigApplicationContext
java.lang.Object
org.springframework.core.io.DefaultResourceLoader
org.springframework.context.support.AbstractApplicationContext
org.springframework.context.support.GenericApplicationContext
org.springframework.context.annotation.AnnotationConfigApplicationContext
- All Implemented Interfaces:
Closeable,AutoCloseable,BeanFactory,HierarchicalBeanFactory,ListableBeanFactory,BeanDefinitionRegistry,AnnotationConfigRegistry,ApplicationContext,ApplicationEventPublisher,ConfigurableApplicationContext,Lifecycle,MessageSource,AliasRegistry,EnvironmentCapable,ResourceLoader,ResourcePatternResolver
public class AnnotationConfigApplicationContext
extends GenericApplicationContext
implements AnnotationConfigRegistry
Standalone application context, accepting component classes as input —
in particular
@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.
- Since:
- 3.0
- Author:
- Juergen Hoeller, Chris Beams
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.core.io.DefaultResourceLoader
DefaultResourceLoader.ClassPathContextResource -
Field Summary
Fields inherited from class org.springframework.context.support.AbstractApplicationContext
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAMEFields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIXFields inherited from interface org.springframework.context.ConfigurableApplicationContext
APPLICATION_STARTUP_BEAN_NAME, CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SHUTDOWN_HOOK_THREAD_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAMEFields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIXFields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new AnnotationConfigApplicationContext that needs to be populated throughregister(java.lang.Class<?>...)calls and then manually refreshed.AnnotationConfigApplicationContext(Class<?>... componentClasses) Create a new AnnotationConfigApplicationContext, deriving bean definitions from the given component classes and automatically refreshing the context.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.Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegister one or more component classes to be processed.<T> voidregisterBean(String beanName, Class<T> beanClass, Supplier<T> supplier, BeanDefinitionCustomizer... customizers) 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).voidPerform a scan within the specified base packages.voidsetBeanNameGenerator(BeanNameGenerator beanNameGenerator) Provide a customBeanNameGeneratorfor use withAnnotatedBeanDefinitionReaderand/orClassPathBeanDefinitionScanner, if any.voidsetEnvironment(ConfigurableEnvironment environment) Propagate the given customEnvironmentto the underlyingAnnotatedBeanDefinitionReaderand