Spring에서 빈이 초기화된 후 혹은 소멸 이전에 특정 메소드가 수행되도록 설정이 가능하다.
■ Annotation 방식
수행하고자 하는 메서드에 @PostConstruct, @PreDestroy 어노테이션을 설정해 주면 된다.
- @PostConstruct : 빈이 초기화된 후 수행
- @PreDestroy : 빈이 소멸되기 전 수행
public class ExampleClass{
@PostConstruct
public void postMethod() {
// 초기화 내용
}
@PreDestroy
public void preMethod() {
// 종료처리할 내용
}
}
■ XML 설정 방식
* @PostConstruct Annotation과 XML에서 init-method 설정을 모두 하였을 때에는
@PostConstruct가 먼저 수행된다고 한다.
'IT > Spring' 카테고리의 다른 글
| JSP에서 properties에 선언된 값 불러오기 (0) | 2017.02.14 |
|---|---|
| Root Application Context와 Servlet Context (0) | 2015.08.18 |
| Spring @Scheduled 어노테이션 (0) | 2015.07.06 |
WRITTEN BY
- Dukejin
If you don't walk today, you will have to run tomorrow. Try hard, Try hard!
,




