더북(TheBook)

콜백 메서드를 사용하는 코드와 콜백 인터페이스를 사용하는 코드 사이에는 큰 차이가 없습니다. 예제 4-9와 위 예제는 심지어 같은 메서드 이름을 사용했습니다. 이 예제에서 사용하는 구성 파일은 다음과 같습니다.

예제 4-12 DestructiveBeanWithInterface 빈 구성([[disposable-bean]] app-context-xml.xml)

<beans ...>

    <bean id="destructiveBean"
        class="com.apress.prospring5.ch4.DestructiveBeanWithInterface"
        p:filePath=
    "#{systemProperties['java.io.tmpdir']}#{systemProperties['file.separator']}test.txt"/>
</beans>

 

예제 4-10과 클래스 이름이 다른 것 외의 차이점은 destroy-methodinit-method 애트리뷰트가 사라졌다는 것입니다. 이 예제를 실행하면 다음과 같은 결과가 출력됩니다.

빈을 초기화합니다.
파일 존재여부: true
destroy() 호출 시작
빈을 소멸합니다.
파일 존재여부: false
destroy() 호출 종료
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.