sliver__

스프링(Spring) - 스프링 컨테이너(Spring Container)와 스프링 빈(Spring Bean) 본문

CS/Spring

스프링(Spring) - 스프링 컨테이너(Spring Container)와 스프링 빈(Spring Bean)

sliver__ 2022. 1. 16. 10:42
728x90

 

Spring Container 생성

 

ApplicationContext applicationContext = new AnnotationConfigApplicationContext(***.class);

 

  • ApplicationContext를 스프링 컨테이너라고 한다.
  • ApplicationContext는 인터페이스이다.
  • Annotation 기반 자바 설정 클래스로 만들 수 있다.
  • 스프링 컨테이너 안에 스프링 빈 저장소가 있다.
  • <Key, Value> 형태로 저장되며 함수 이름이 Key 객체를 Value로 저장해둔다
빈 이름 빈 객체
   
Function Name  Instance Object
   

 

Spring Bean

 

  • 빈 이름은 항상 다른 이름을 부여해야 한다. 
  • 빈 이름을 직접 부여할 수도 있다 . (ex) @Bean(name="mmm")
  • 스프링 컨테이너는 설정 정보를 참고해서 의존관계를 주입한다.
  • ac.getBeanDefinitionNames : 스프링에 등록된 모든 빈 이름을 조회한다.
  • ac.getBean() : 빈 이름으로 빈 객체를 조회한다.
728x90
Comments