ApplicationContext applicationContext
= new AnnotationConfigApplicationContext(AppConfig.class);
= Spring Container
+ Interface
+ ApplicationContext Interface의 구현체
+ 구성 정보
+ 스프링 빈 등록
@Bean
public MemberService memberService() {
return new MemberserviceImpl(memberRepository));
}
+ 빈 이름 : memberService
+ 빈 객체 : MemberServiceImpl@x01
🔔 빈 이름은 항상 다른 이름 부여!!!
cf) 스프링은 빈을 생성하고 의존관계를 주입하는 단계가 나누어져 있음.
이렇게 자바코드로 스프링 빈을 등록하면 생성자를 호출하면서 의존관계 주입(DI)도 한번에 처리됨
//1)
ac.getBean(beanName, beanType)
//2)
ac.getBean(beanType)
조회 대상 스프링 빈이 없으면 예외 발생
NoSuchBeanDefinitionException: No bean named 'xxxxx' available
+ 부모타입으로 조회하면, 자식타입도 함께 조회
ex Object type으로 조회하면, 모든 스프링 빈을 조회한다.
BeanFactory
getBean() 제공 AppplicationContext
부가기능 제공부가기능

역할과 구현을 개념적으로 나눔 