AnnotationConfigApplicationContext class
ApplicationContext implementation that supports annotation-based configuration.
This context extends GenericApplicationContext to add comprehensive support for annotation-driven dependency injection and component configuration in the Jetleaf framework.
Key Features:
- @Component Scanning: Automatically discovers and registers annotated classes
- @Configuration Support: Processes configuration classes with @Pod methods
- @Profile Activation: Conditionally registers components based on active profiles
- @Autowired Injection: Automatically wires dependencies between services
- Package Scanning: Scans specified packages for annotated components
- Annotation Processors: Built-in processors for common annotations
- Environment Integration: Profile-based conditional bean registration
Architecture:
The context combines programmatic registration with automatic classpath scanning to provide a flexible configuration system. It uses specialized processors to handle different annotation types and integrates with the Jetleaf environment system for profile-based activation.
Usage Example:
final context = AnnotationConfigApplicationContext();
// Register configuration classes
context.register(AppConfig);
context.register(DatabaseConfig);
// Scan packages for components
context.scan(['package:example/services', 'package:example/repositories']);
// Set active profiles
context.getEnvironment().setActiveProfiles(['production', 'database']);
// Initialize the context
await context.refresh();
// Retrieve components
final userService = await context.get<UserService>();
Annotation Support:
@Component
,@Service
,@Repository
- Component stereotypes@Configuration
- Configuration classes with@Pod
methods@Autowired
- Dependency injection points@Qualifier
- Dependency disambiguation@Profile
- Conditional registration@EventListener
- Event handling methods
See also:
- GenericApplicationContext for the base application context functionality
- AnnotationConfigRegistry for the annotation configuration interface
AnnotatedPodDefinitionReader
for annotation processing
- Inheritance
-
- Object
- SmartLifecycle
- ConfigurableApplicationContext
- AbstractApplicationContext
- GenericApplicationContext
- AnnotationConfigApplicationContext
- Implemented types
Constructors
- AnnotationConfigApplicationContext()
- ApplicationContext implementation that supports annotation-based configuration.
- AnnotationConfigApplicationContext.all(ApplicationContext? parent, DefaultListablePodFactory? podFactory)
- Creates a new AnnotationConfigApplicationContext with a parent context and optional pod factory.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger → Log
-
The logger associated with this application context.
finalinherited
- podFactory ↔ ConfigurableListablePodFactory?
-
The pod factory associated with this application context.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addApplicationListener(
ApplicationEventListener< ApplicationEvent> listener) → Future<void> -
Adds an ApplicationEventListener to be notified of all ApplicationEvents.
inherited
-
addPodAwareProcessor(
PodAwareProcessor processor) → void -
Registers a new pod-aware processor.
inherited
-
addPodFactoryPostProcessor(
PodFactoryPostProcessor processor) → void -
Adds a PodFactoryPostProcessor to be applied to the pod factory.
inherited
-
addSingletonCallback(
String name, Class type, Consumer< Object> callback) → void -
Add a callback to be executed when the singleton associated with
name
is initialized.inherited -
cancelRefresh(
PodException exception) → Future< void> -
Cancels the refresh process due to the provided
PodException
.inherited -
clearMetadataCache(
) → void -
Clears the internal metadata cache.
inherited
-
clearSingletonCache(
) → void -
Clears all cached singleton pods.
inherited
-
close(
) → Future< void> -
Closes this resource, relinquishing any underlying resources.
inherited
-
completeRefresh(
) → Future< void> -
Completes the refresh process for the given
ConfigurableListablePodFactory
.inherited -
containsDefinition(
String name) → bool -
Returns
true
if this registry contains a pod with the givenname
.inherited -
containsLocalPod(
String podName) → Future< bool> -
Checks if a pod with the given name is registered locally in this factory.
inherited
-
containsPod(
String podName) → Future< bool> -
Checks if a pod with the given name is registered in the factory.
inherited
-
containsSingleton(
String name) → bool -
Returns
true
if this registry contains a pod with the givenname
.inherited -
containsType(
Class type, [bool allowPodProviderInit = false]) → Future< bool> -
Checks if the factory contains a pod of the specified type.
inherited
-
copyConfigurationFrom(
ConfigurablePodFactory otherFactory) → void -
Copies configuration from another factory.
inherited
-
destroyPod(
String podName, Object podInstance) → Future< void> -
Destroys a pod instance by name and instance.
inherited
-
destroyPods(
) → Future< void> -
Destroys all managed pods in the given
ConfigurableListablePodFactory
.inherited -
destroyScopedPod(
String podName) → void -
Destroys all pods in the specified scope.
inherited
-
destroySingletons(
) → void -
Destroys all singleton pods in the factory.
inherited
-
doClose(
) → Future< void> -
Template method for actual cleanup logic when the context is closed.
inherited
-
doGetFreshPodFactory(
) → Future< ConfigurableListablePodFactory> -
Returns a fresh
ConfigurableListablePodFactory
for this context.inherited -
doStart(
) → Future< void> -
Template method invoked during start to perform startup logic.
inherited
-
doStop(
) → Future< void> -
Template method invoked during stop to perform shutdown logic.
inherited
-
findAllAnnotationsOnPod<
A> (String podName, Class< A> type) → Future<Set< A> > -
Finds all annotations of the specified type on a pod.
inherited
-
findAnnotationOnPod<
A> (String podName, Class< A> type) → Future<A?> -
Finds a specific annotation on a pod.
inherited
-
finishPodFactoryInitialization(
) → Future< void> -
Finalizes the initialization of the
ConfigurableListablePodFactory
.inherited -
finishRefresh(
) → Future< void> -
Template method invoked during refresh to complete the refresh process.
override
-
get<
T> (Class< T> type, [List<ArgumentValue> ? args]) → Future<T> -
Retrieves a pod instance by its type with optional arguments.
inherited
-
getAliases(
String podName) → List< String> -
Retrieves all alias names for the specified pod.
inherited
-
getAllowCircularReferences(
) → bool -
Retrieves the current circular reference setting.
inherited
-
getAllowDefinitionOverriding(
) → bool -
Retrieves the current definition overriding setting.
inherited
-
getAllowRawInjectionEvenWhenWrapped(
) → bool -
Retrieves the current raw injection despite wrapping setting.
inherited
-
getApplicationEventBus(
) → ApplicationEventBus -
Returns the ApplicationEventBus currently associated with
this application context.
inherited
-
getApplicationName(
) → String -
Returns the name of this application.
inherited
-
getApplicationStartup(
) → ApplicationStartup -
Defines a contract for components that are aware of and can interact with
an
ApplicationStartup
strategy.inherited -
getConversionService(
) → ConversionService -
Retrieves the currently assigned
ConversionService
.inherited -
getDefinition(
String name) → PodDefinition -
Retrieve the pod registered under
name
.inherited -
getDefinitionNames(
) → List< String> -
Returns a list of all pod names currently registered.
inherited
-
getDisplayName(
) → String -
Returns the display name of this application context.
override
-
getEnvironment(
) → Environment -
🫘 Returns the
Environment
associated with the current context.inherited -
getId(
) → String -
Returns a unique identifier for this application context.
override
-
getIsRefreshed(
) → bool -
Returns true if the application context has been refreshed.
inherited
-
getMainApplicationClass(
) → Class< Object> -
Returns the main application class.
inherited
-
getMergedPodDefinition(
String podName) → RootPodDefinition -
Retrieves the merged pod definition for the specified pod name.
inherited
-
getMessage(
String code, {List< Object> ? args, Locale? locale, String? defaultMessage}) → String -
Retrieve a message for the given code.
inherited
-
getMessageSource(
) → MessageSource -
Returns the configured MessageSource.
inherited
-
getNamedObject(
String podName, [List< ArgumentValue> ? args]) → Future<Object> -
Retrieves a pod as a generic Object by its name with optional arguments.
inherited
-
getNumberOfPodDefinitions(
) → int -
Returns the total number of pods registered.
inherited
-
getObject(
Class< Object> type, [List<ArgumentValue> ? args]) → Future<Object> -
Retrieves a pod as a generic Object by its type with optional arguments.
inherited
-
getPackageName(
) → String -
Represents an abstraction for identifying the package that an object,
resource, or service belongs to.
inherited
-
getParent(
) → ApplicationContext? -
Returns the parent context, if any.
inherited
-
getParentFactory(
) → PodFactory? -
Retrieves the parent factory in the hierarchy, if any.
inherited
-
getPhase(
) → int -
Interface for objects that may participate in a phased process
such as lifecycle management.
inherited
-
getPod<
T> (String podName, [List< ArgumentValue> ? args, Class<T> ? type]) → Future<T> -
Retrieves a pod instance by its name with optional arguments.
inherited
-
getPodAwareProcessorCount(
) → int -
Gets the number of registered pod-aware processors.
inherited
-
getPodAwareProcessors(
) → List< PodAwareProcessor> -
Retrieves all registered pod-aware processors.
inherited
-
getPodClass(
String podName) → Future< Class> -
Retrieves the Class object for the specified pod name.
inherited
-
getPodExpressionResolver(
) → PodExpressionResolver? -
Retrieves the current expression resolver.
inherited
-
getPodFactory(
) → ConfigurableListablePodFactory -
🫘 Returns the underlying
ConfigurableListablePodFactory
.inherited -
getPodFactoryPostProcessors(
) → List< PodFactoryPostProcessor> -
The list of PodFactoryPostProcessors to be applied to the pod factory.
inherited
-
getPodNames(
Class type, {bool includeNonSingletons = false, bool allowEagerInit = false}) → Future< List< String> > -
Retrieves all pod names for pods of the specified type.
inherited
-
getPodNamesForAnnotation<
A> (Class< A> type) → Future<List< String> > -
Retrieves pod names for pods annotated with the specified annotation type.
inherited
-
getPodNamesIterator(
) → Iterator< String> -
Returns an iterator over all pod names in the factory.
inherited
-
getPodsOf<
T> (Class< T> type, {bool includeNonSingletons = false, bool allowEagerInit = false}) → Future<Map< String, T> > -
Retrieves all pods of the specified type as a map of name to instance.
inherited
-
getPodsWithAnnotation<
A> (Class< A> type) → Future<Map< String, Object> > -
Retrieves pods with the specified annotation as a map of name to instance.
inherited
-
getProvider<
T> (Class< T> type, {String? podName, bool allowEagerInit = false}) → Future<ObjectProvider< T> > -
Retrieves a provider for a pod, allowing for lazy or eager initialization.
inherited
-
getRegisteredScope(
String scopeName) → PodScope? -
Retrieves a registered scope by name.
inherited
-
getRegisteredScopeNames(
) → List< String> -
Retrieves all registered scope names.
inherited
-
getSingleton(
String name, {bool allowEarlyReference = true, ObjectFactory< Object> ? factory}) → Future<Object?> -
Retrieve the pod registered under
name
.inherited -
getSingletonCount(
) → int -
Returns the total number of pods registered.
inherited
-
getSingletonNames(
) → List< String> -
Returns a list of all pod names currently registered.
inherited
-
getStartTime(
) → DateTime -
Returns the startup time of this context as a DateTime.
inherited
-
initApplicationEventBus(
) → Future< void> -
Initializes the ApplicationEventBus for this context.
inherited
-
initLifecycleProcessor(
) → Future< void> -
Initializes the
LifecycleProcessor
for this context.inherited -
initMessageSource(
) → Future< void> -
Initializes the MessageSource for this context.
inherited
-
invokePodFactoryPostProcessors(
) → Future< void> -
Invokes all registered pod factory post-processors on the given
ConfigurableListablePodFactory
.inherited -
isActive(
) → bool -
Returns whether this application context is currently active.
inherited
-
isActuallyInCreation(
String podName) → bool -
Checks if a pod with the given name is currently being created.
inherited
-
isAutoStartup(
) → bool -
An extension of the Lifecycle interface for those objects that require
to be started upon ApplicationContext refresh and/or shutdown in a
particular order.
inherited
-
isAutowireCandidate(
String podName, DependencyDescriptor descriptor) → bool -
Checks if a pod is a candidate for autowiring for the given dependency.
inherited
-
isCachePodMetadata(
) → bool -
Checks if pod metadata caching is enabled.
inherited
-
isClosed(
) → bool -
Returns whether this application context has been closed.
inherited
-
isNameInUse(
String name) → Future< bool> -
Returns
true
ifname
is currently in use in this registry.inherited -
isPodProvider(
String podName, [RootPodDefinition? rpd]) → Future< bool> -
Checks if the specified pod name refers to a pod provider.
inherited
-
isPrototype(
String podName) → Future< bool> -
Checks if the specified pod is configured as a prototype.
inherited
-
isRunning(
) → bool -
Check whether this component is currently running.
inherited
-
isSingleton(
String podName) → Future< bool> -
Checks if the specified pod is configured as a singleton.
inherited
-
isTypeMatch(
String name, Class typeToMatch, [bool allowPodProviderInit = false]) → Future< bool> -
Checks if the pod with the specified name matches the given type.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
postProcessPodFactory(
) → Future< void> -
Post-processes the
ConfigurableListablePodFactory
for this context.override -
preInstantiateSingletons(
) → Future< void> -
Pre-instantiates all singleton pods.
inherited
-
preparePodFactory(
) → Future< void> -
Prepares the
ConfigurableListablePodFactory
for this context.override -
prepareRefresh(
) → Future< void> -
Prepares the application context for a refresh.
inherited
-
publishEvent(
ApplicationEvent event) → Future< void> -
Publishes the given
event
to all registered ApplicationEventListeners.inherited -
refresh(
) → Future< void> -
Refreshes this application context:
inherited
-
register(
PodRegistrar registrar) → void -
Registers a
registrar
that declares pods into this registry.inherited -
registerAlias(
String name, String alias) → void -
Registers an alias for an existing name in the registry.
inherited
-
registerAnnotationConfigProcessors(
[Object? source]) → Future< void> - Registers the internal annotation configuration processors.
-
registerClass(
{List< Class< ? classes, Class<Object> >Object> ? mainClass}) → Future<void> -
Behavior
override
-
registerDefinition(
String name, PodDefinition pod) → Future< void> -
Register a new
pod
under the givenname
.inherited -
registerIgnoredDependency(
Class type) → void -
Registers a dependency type that should be ignored during autowiring.
inherited
-
registerListeners(
) → Future< void> -
Registers all ApplicationEventListener pods in the
ConfigurableListablePodFactory
.inherited -
registerPod<
T> (Class< T> podClass, {Consumer<Spec< ? customizer, String? name}) → Future<T> >void> -
Registers a pod of type
T
in the registry.inherited -
registerPodAwareProcessors(
) → Future< void> -
Registers all PodAware processors into the given
ConfigurableListablePodFactory
.inherited -
registerResolvableDependency(
Class type, [Object? autowiredValue]) → void -
Registers a resolvable dependency for autowiring.
inherited
-
registerScope(
String scopeName, PodScope scope) → void -
Registers a new scope with the given name.
inherited
-
registerSingleton(
String name, Class type, {ObjectHolder< Object> ? object, ObjectFactory<Object> ? factory}) → Future<void> -
Register a new
pod
under the givenname
.inherited -
removeDefinition(
String name) → Future< void> -
Remove the pod associated with
name
.inherited -
removeSingleton(
String name) → void -
Remove the pod associated with
name
.inherited -
resetCommonCaches(
) → Future< void> -
Resets common internal caches maintained by the container.
inherited
-
resolveDependency(
DependencyDescriptor descriptor, [Set< String> ? candidates]) → Future<Object?> -
Resolves a dependency based on the provided descriptor.
inherited
-
scan(
List< String> basePackages) → Future<void> -
Scans the given base packages for annotated components
override
-
setAllowCircularReferences(
bool value) → void -
Allows or disallows circular references between pods.
inherited
-
setAllowDefinitionOverriding(
bool value) → void -
Allows or disallows overriding of pod definitions.
inherited
-
setAllowRawInjectionEvenWhenWrapped(
bool value) → void -
Allows or disallows raw injection despite wrapping.
inherited
-
setApplicationEventBus(
ApplicationEventBus applicationEventBus) → void -
Sets the ApplicationEventBus for this application context.
inherited
-
setApplicationStartup(
ApplicationStartup applicationStartup) → void -
Defines a contract for components that are aware of and can interact with
an
ApplicationStartup
strategy.inherited -
setCachePodMetadata(
bool cachePodMetadata) → void -
Enables or disables caching of pod metadata for performance optimization.
inherited
-
setConversionService(
ConversionService conversionService) → void -
Sets an assigned
ConversionService
.inherited -
setEnvironment(
Environment environment) → void -
Sets the
Environment
that this component runs in.inherited -
setMainApplicationClass(
Class< Object> mainApplicationClass) → void -
Sets the main application class.
inherited
-
setMessageSource(
MessageSource messageSource) → void -
Sets the MessageSource used for resolving internationalized messages.
inherited
-
setParent(
ApplicationContext parent) → void -
Sets the parent of this application context.
inherited
-
setParentFactory(
PodFactory? parentFactory) → void -
Sets the parent factory for this hierarchical factory.
inherited
-
setPodExpressionResolver(
PodExpressionResolver? valueResolver) → void -
Sets the expression resolver for resolving expressions in pod definitions.
inherited
-
start(
) → FutureOr< void> -
A common interface defining methods for start/stop lifecycle control.
inherited
-
stop(
[Runnable? callback]) → FutureOr< void> -
Stop this component, typically in a synchronous fashion.
inherited
-
supports(
ApplicationType applicationType) → bool -
Returns whether this context supports the given
applicationType
.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- APPLICATION_CONTEXT_POD_NAME → String
-
Pod name for the registered application context.
final
- APPLICATION_MODULE_PROCESSOR_POD_NAME → String
-
Pod name for the internal application module processor.
final
- AUTOWIRED_ANNOTATION_PROCESSOR_POD_NAME → String
-
Pod name for the internal autowired annotation processor.
final
- COMMON_ANNOTATION_PROCESSOR_POD_NAME → String
-
Pod name for the internal common annotation processor.
final
- CONFIGURATION_ANNOTATION_PROCESSOR_POD_NAME → String
-
Pod name for the internal configuration annotation processor.
final
- ENVIRONMENT_POD_NAME → String
-
Pod name for the internal environment instance.
final
- EVENT_LISTENER_METHOD_PROCESSOR_POD_NAME → String
-
Pod name for the internal event listener method processor.
final