InitializingBean 인터페이스
빈 객체의 라이프 사이클과 관련된 인터페이스 중에서 가장 많이 사용되는 것 중의 하나가
org.springframework.beans.factory.InitializingBean 인터페이다.
객체를 생성하고 프로퍼티를 초기화 하고, 컨테이너관련 설정을 완료한 뒤에 호출되는 메서드를 정의하고 있다.
public interface InitializingBean {
public void afterPropertiesSet() throws Exception
}
afterPropertiesSet() 메서드는 주로 빈 객체의 프로퍼티가 모두 올바르게 설정되었는지의 여부를 검사하는 용도
(프로퍼티 값을 검증하는 코드를 구현)
public abstract class AbstractUrlBasedView extends AbstractView implements InitializingBean {
...
public void afterPropertiesSet() throws Exception {
if( getUrl() == null ) {
throw new lllegalArgumentException("Property 'url' is required");
}
}
...
}
'프로그래밍 > SPRING 3.X' 카테고리의 다른 글
AspectJ의 Pointcut 표현식 (0) | 2013.07.15 |
---|---|
Spring Advice 태그 (0) | 2013.07.15 |
스프링에서 <constructor-arg>사용 (0) | 2013.06.24 |
이클립스에서 git pull 나는 오류중 The current branch is not configured for pull No value for key branch.master.merge found in configuration 해결법 (0) | 2013.06.20 |
토비의 스프링 (0) | 2013.03.25 |