스프링 BeanDefinition

wangjh789·2022년 7월 24일
0

스프링이 자바코드나 xml파일에서 설정정보를 가져와 빈을 만들 수 있는 이유는 추상화에 있다.

AnnotationConfigApplicationContext

public class AnnotationConfigApplicationContext extends 
		GenericApplicationContext implements AnnotationConfigRegistry {

	private final AnnotatedBeanDefinitionReader reader;

AnnotatedBeanDefinitionReader 는 자바코드를 읽고 빈당 하나의 BeanDefinition 을 생성한다.

GenericXmlApplicationContext

public class GenericXmlApplicationContext extends GenericApplicationContext {

	private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this);

XmlBeanDefinitionReader 는 xml 파일을 읽고 빈당 하나의 BeanDefinition 을 생성한다.

BeanDefinition

BeanDefinition, 빈의 메타정보

beanDefinition = Root bean: class [null]; scope=; abstract=false; 
lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true;
primary=false; factoryBeanName=appConfig; factoryMethodName=memberService;
initMethodName=null; destroyMethodName=(inferred); defined in 
hello.core.AppConfig

이처럼 스프링은 다양한 설정정보를 BeanDefinition으로 추상화해서 사용한다.

참고로 getBeanDefinition() 함수는 ApplicationContext에서는 사용할 수 없다.

AnnotationConfigApplicationContext ac = new 
		AnnotationConfigApplicationContext(AppConfig.class);
profile
기록

0개의 댓글