진취적 삶
6.1 컨테이너 초기화와 종료 본문
스프링 컨테이너는 초기화와 종료라는 라이프 사이클을 갖는다.
public class Main2 {
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx =
new AnnotationConfigApplicationContext(AppContext.class);
Greeter g = ctx.getBean("greeter", Greeter.class);
String msg = g.greet("스프링");
System.out.println(msg);
ctx.close();
}
}
AnnotationConfigApplicationContext 생성자를 이용해서 컨텍스트 객체를 생성할때
스프링 컨테이너를 초기화 한다.
close() 메서드로 컨테아너 종료
- 컨테이너의 초기화 → 빈 객체의 생성, 의존 주입 ,초기화
- 컨테이너 종료 → 빈 객체의 소멸
'스프링 5 프로그래밍 입문 > 6.빈 라이플사이클봐 범위' 카테고리의 다른 글
6.2 스프링 빈 객체의 라이프사이클 (0) | 2023.09.06 |
---|---|
6.3 빈 객체의 생성과 관리 범위 (0) | 2023.09.06 |