제어의 역전
객체에 대한 제어권이 컨테이너로 역전
프로그램을 실행하는데 필요한 객체에 해단 생성, 변경이 개발자가 직접하는 것이 아닌 프로그램을 구동하는 컨테이너가 직접 관리하는 것을 말함
Spring는 IoC를 통해 필요한 객체의 생성부터 생명주기까지 객체에 대한 관리를 직접함
Spring에서 관리하는 객체를 Bean(빈)이라고 하며 Bean(빈)을 관리한다는 의미로 컨테이너를 Bean Factory라고 함
의존성 주입
어떤 객체에 스프링 컨테이너가 다른 객체와 의존성을 맺어주는 행위
IoC의 핵심 기술이라고 할 수 있으며 사용하는 객체를 직접 생성하여 만드는 것이 아니라 컨테이너가 빈의 설정 정보를 읽어와 자동으로 해당 객체에 연결하는 것
의존성을 받게 되면 객체 수정시 소스 코드의 수정을 최소화 할 수 있음
<constructor-arg>
를 인자의 개수만큼 추가해야 함<bean id = "불러올 객체 이름" class = "클래스 풀 네임">
<constructor-arg index = "0" value = "OOO"/>
<constructor-arg index = "OOO" ref = "OOO"/>
</bean>
<bean id = "student" class = "com.kh.spring.person.model.vo.student">
<constructor-arg index = "0" value = "홍길동"/>
<constructor-arg index = "0" ref = "money"/>
</bean>
<bean id = "money" class = "com.kh.spring.wallet.model.vo.Wallet"/>
<property>
태그에서 의존 관계를 주입할 필드 값을 name 속성에 지정해야 함<bean id = "객체 이름" class = "클래스 풀 네일">
<property name = "name" value = "OOO"/>
<property name = "name" ref = "OOO"/>
</bean>
<bean id = "student" class = "com.kh.spring.person.model.vo.student">
<property name = "name" value = "홍길동"/>
<property name = "wallet" ref = "money"/>
</bean>
<bean id = "money" class = "com.kh.spring.wallet.model.vo.Wallet"/>
ref :