<bean id="userinfo" class="com.jd.vo.UserInfo" lazy-init="true" scope="singleton" init-method="init" destroy-method="destroy">
<property name="name" value="Tom"></property></bean>
生命周期主要分为四个阶段 实例化、属性赋值、初始化以及销毁。并仅仅只对单体来说既scope的值是singleon。
ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicatiion.xml");
Object object=applicationContext.getBean("userinfo");
System.out.println(object);
applicationContext.close();
static {
System.out.println("静态");
}
{
System.out.println("动态");
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void init() {
System.out.println("init");
}
public void destroy() {
System.out.println("destroy");
}
public UserInfo(){
System.out.println("输出对象");
}
最后的输出是依次输出静态代码块,非静态代码块,构造方法 ,setter方法,init方法,destroy方法。
静态
动态
输出对象
setter
init
com.jd.vo.UserInfo@f5e5e3
二月 22, 2020 8:48:39 下午 org.springframework.context.support.ClassPathXmlApplicationContext doClose
信息: Closing org.springframework.context.support.ClassPathXmlApplicationContext@817b38: startup date [Sat Feb 22 20:48:39 CST 2020]; root of context hierarchy
destroy