더북(TheBook)

다시 말하지만 앞서 소개한 구성 파일은 ‘4.3.1 빈 생성 시 메서드 실행하기’에서 본 구성 파일과 크게 다르지 않습니다. 주요 차이점은 init-method 애트리뷰트가 빠졌다는 것입니다. SimpleBeanWithInterfaceInitializingBean 인터페이스를 구현했으므로 스프링이 초기화 콜백으로 어느 메서드를 호출해야 할지 알기 때문에 초기화 메서드를 지정하는 추가 구성이 필요 없습니다. 예제 실행 결과는 다음과 같습니다.

 초기화
      이름: John Mayer
      나이: 39
 초기화
기본 가수 이름 설정
      이름: Eric Clapton
      나이: 72
 초기화
 구성 도중 에러 발생: Error creating bean with name 'singerThree' defined in class path resource [spring/app-context-xml.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: class com.apress.prospring5.ch4.SingerWithInterface  타입에는 반드시 age 프로퍼티를 설정해야 합니다.
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.