AnnotationConfigApplicationContext: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
Line 12: Line 12:


=Example=
=Example=
<syntaxhighlight lang='java'>
private static ApplicationContext APPLICATION_CONTEXT = new AnnotationConfigApplicationContext("playground.spring");
...
AComponent c = APPLICATION_CONTEXT.getBean(AComponent.class);
</syntaxhighlight>

Latest revision as of 20:21, 23 November 2018

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);