Метод @PostConstruct не вызывается в 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");
}
и конфигурационный файл вот так:
<bean id="SampleBean" class="com.springexample.SampleBean">
<property name="beanOne" ref="beanOneOne"></property>
<property name="beanTwo" ref="beanTwoOne"></property>
</bean>
И у меня нет атрибута default-init-method, установленного для тега beans.
Любое тело может сказать, почему метод @PostConstruct не вызывается.
1 ответ
Решение
Тебе нужно <context:annotation-config/>
(или же <context:component-scan/>
) включить @PostConstruct
обработки.