The @PostConstruct method is not called in Spring

SampleBean:

package com.springexample; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; public class SampleBean { private BeanTypeOne beanOne; private BeanTypeTwo beanTwo; public void init() { System.out.println("This is from the init() method"); } @PostConstruct public void initAnnotation() { System.out.println("This is from the initAnnotation() method"); } 

and configuration file:

 <bean id="SampleBean" class="com.springexample.SampleBean"> <property name="beanOne" ref="beanOneOne"></property> <property name="beanTwo" ref="beanTwoOne"></property> </bean> 

And I don't have the default-init-method attribute set in the beans tag.

Can any body say why the @PostConstruct method is not called.

+21
spring
Aug 08 '10 at 13:00
source share
1 answer

You need <context:annotation-config/> (or <context:component-scan/> ) to enable @PostConstruct processing.

+41
Aug 08 '10 at 13:24
source share



All Articles