본문 바로가기
개발자의 정보/Java & framework

Bean의 생성과 소멸에 발생되는 이벤트

by pastory 2020. 2. 13.

Bean 이 생성된 직후 그리고 소멸직전 이벤트가 발생하여 해당 이벤트에 내가 원하는 동작을 넣을 수 있다.

 

@PostConstruct: call after construct

@PreDestroy: call before destroy

@PostConstruct
public void init() {
	System.out.println("hello.");
}

@PreDestroy
public void destroy() {
	System.out.println("bye.");
}

가끔이지만 아주 유용하게 사용되는 기능이니 잘 기억해 두는 것이 좋겠다.

 

댓글