이 프로그램은 init-method를 사용한 코드와 거의 같으며, 차이점은 init() 메서드 위에 @PostConstruct 애너테이션을 적용한 것뿐입니다. 초기화 메서드 이름은 아무거나 사용할 수 있습니다. 애너테이션을 적용했으므로 구성 파일에 context 네임스페이스가 제공하는 <context:annotation-config> 태그를 추가해야 합니다.
예제 4-7 애너테이션을 사용하도록 구성 변경([[post-construct]] app-context-annotation.xml)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" default-lazy-init="true"> <context:annotation-config/> <bean id="singerOne" class="com.apress.prospring5.ch4.SingerWithJSR250" p:name="John Mayer" p:age="39"/> <bean id="singerTwo" class="com.apress.prospring5.ch4.SingerWithJSR250" p:age="72"/> <bean id="singerThree" class="com.apress.prospring5.ch4.SingerWithJSR250" p:name="John Butler"/> </beans>