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");
}
Run Code Online (Sandbox Code Playgroud)
和配置文件如下:
<bean id="SampleBean" class="com.springexample.SampleBean">
<property name="beanOne" ref="beanOneOne"></property>
<property name="beanTwo" ref="beanTwoOne"></property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我没有在beans标记上设置default-init-method属性.
任何人都可以告诉为什么@PostConstruct方法不会被调用.
| 归档时间: |
|
| 查看次数: |
22839 次 |
| 最近记录: |