#Spring
Spring Bean Life Cycle
뚱보리루
2019. 1. 6. 17:28
1. Bean life cycle
- GenericXmlApplicationContext ctx = new GenericXmlApplicationContext("classpath:applicationContext.xml"); 선언 시, Spring Container가 메모리 상에 생성되고 Bean 객체 생성 및 주입.
- ctx.close() 시, Spring Container가 Bean 객체와 함께 소멸됨.
2. Interface를 이용한 Bean 객체 생성되는 과정에서, 소멸되는 과정에서 어떠한 작업 하기.
- 생성되는 과정 : Interface InitializingBean (e.g. db연결, network 설정 등)
- AfterPropertiesSet() 구현
- 소멸되는 과정 : Interface DisposableBean
- Destroy() 구현
3. Spring 설정 파일을 이용한 Bean 객체 생성되는 과정에서, 소멸되는 과정에서 어떠한 작업 하기.
- 생성되는 과정 : init-method
- 소멸되는 과정 : destroy-method
[참조] 자바 스프링 프레임워크(Renewal Ver.) – 신입 프로그래머를 위한 강좌 (Influence 강좌입니다. 미리보기에 제공되는 내용이니 직접 강좌를 보셔도 좋을 것 같습니다.)