AnnotationConfigApplicationContext

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

AnnotationConfigApplicationContext is a standalone application context that accepts @Configuration-annotated classes, as well as stereotype-annotated classes and JSR-330 compliant classes using javax.inject annotations as input. 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. Component classes can be registered one by one using register(Class), or they can be detected via the component scan mechanism, triggered by scan(String) method. This application context is used by the Spring Boot applications.

Example

private static ApplicationContext APPLICATION_CONTEXT = new AnnotationConfigApplicationContext("playground.spring");
...
AComponent c = APPLICATION_CONTEXT.getBean(AComponent.class);