메뉴 건너뛰기

조회 수 4996 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부



스프링의 컨테이너가 Bean 객체의 초기화와 소멸에 따라 지정된 메서드를 호출 하는데..

아래의 두가지 인터페이스에서 이 메서드를 정의 하고 있다.


org.springframework.beans.factory.InitializingBean

org.springframework.beans.factory.DisposableBean


만약 Bean 객체의 초기화 및 소멸 과정에 실행하고 싶은 작업이 있다면,

아래와 같이 InitializingBean과 DisposableBean을 구현하고, afterProperiesSet 메서드와 destroy메서드를 구현하면 된다.


public class Bean implements InitializingBean, DisposableBean {
    
    ...
    
    @Override
    public void afterPropertiesSet() throws Exception {
    ...
    }

    @Override
    public void destroy() throws Exception {
    ...
    }
}


또는, 아래와 같이 직접 메서드명을 지정할 수도 있다.

<bean id="class" class="spring.class"
    init-method="초기화 실행 메서드명" destroy-mothod="소멸 실행 메서드명">


@Bean(initMethod="초기화 실행 메서드명", destroyMethod="소멸 실행 메서드명")

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved