Spring Bean의 생명주기(life-cycle)
빈의 생명주기
스프링 컨테이너의 생명주기
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
public static void main(String[] args) {
// 1. 컨테이너 초기화 (생성)
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(AppContext.class);
// 2. 컨테이너 내에 등록된 빈 사용
MyClass mc = context.getBean("myClass", MyClass.class);
mc.print();
// 3. 컨테이너 종료
context.close();
}
}스프링 빈의 생명주기
빈 객체의 초기화와 소멸
외부 클래스를 빈으로 등록하는 경우의 초기화와 소멸
Last updated