AnnotationConfigApplicationContext constructor
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
Creates a new AnnotationConfigApplicationContext with default settings.
The context is initialized with an AnnotatedPodDefinitionReader
for
processing annotated classes but is not refreshed until refresh is called.
Example:
final context = AnnotationConfigApplicationContext();
await context.refresh();
Implementation
AnnotationConfigApplicationContext() : this.all(null, null);