Spring对象生命周期

<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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值