-
빈 생명주기 콜백Spring/스프링 핵심 원리 - 기본편 2022. 8. 6. 18:30
[인프런] 스프링 핵심 원리 - 기본편
스프링은 의존관계 주입이 완료되면 스프링 빈에게 콜백 메서드를 통해서 초기화 시점을 알려주는 다양한 기능을 제공
스프링은 스프링 컨테이너가 종료되기 직전에 소멸 콜백을 줌
=> 안전한 종료 진행 가능
- 초기화 콜백: 빈이 생성되고, 빈의 의존관계 주입이 완료된 후 호출
- 소멸전 콜백: 빈이 소멸되기 직전에 호출
📍@PostConstruct, @PreDestroy
📎 가장 편리한 초기화와 종료 실행 방법
📎 스프링에서 권장하는 방법
📎 스프링에 종속되지 않은 자바 표준임 (javax.annotation.PostConstruct)
📎 외부 라이브러리에는 적용하지 못함 => 외부 라이브러리를 초기화, 종료해야 하면 @Bean의 기능을 사용
'Spring > 스프링 핵심 원리 - 기본편' 카테고리의 다른 글
[인프런] 스프링 핵심 원리 후기 (0) 2022.08.09 빈 스코프 (0) 2022.08.07 의존관계 자동 주입 (0) 2022.08.06 컴포넌트 스캔 (0) 2022.08.05 싱글톤 컨테이너 (0) 2022.08.04