스프링의 가장 핵심은 ApplicationContext 인데 구현체가 다양하다.
AnnotationConfigApplicationContext 이 ApplicationContext 의 구현체 중 가장 단순하면서도 완전한 버전이며, 스프링 핵심 구조가 모두 들어있다고하니 이것부터 한번 살펴보자.
val ctx = AnnotationConfigApplicationContext(MyConfig::class.java)
위 코드부터 시작하여 들어가보도록 하자.
public AnnotationConfigApplicationContext(Class<?>... componentClasses) {
this();
register(componentClasses);
refresh();
}
기본 생성자 호출
AnnotatedBeanDefinitionReader 세팅ClassPathBeanDefinitionScanner 세팅register(MyConfig)
@Override
public void register(Class<?>... componentClasses) {
Assert.notEmpty(componentClasses, "At least one component class must be specified");
StartupStep registerComponentClass = getApplicationStartup().start("spring.context.component-classes.register")
.tag("classes", () -> Arrays.toString(componentClasses));
this.reader.register(componentClasses);
registerComponentClass.end();
}