Spring 接口类InitializingBean实现初始化
InitializingBean接口为bean提供了初始化方法的方式,它只包括afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的时候会执行该方法。
测试程序如下:
1)非注解方式
1
2
3
4
5
6
7
8
9
10
|
import
org.springframework.beans.factory.InitializingBean;
public
class
TestInitializingBean
implements
InitializingBean{
@Override
public
void
afterPropertiesSet()
throws
Exception {
System.out.println(
"ceshi InitializingBean"
);
}
public
void
testInit(){
System.out.println(
"ceshi init-method"
);
}
}
|
配置文件如下:
1
|
<
bean
|