一、生命周期图
1、Instantiate:bean对象实例化
2、Populate properties:封装属性
3、如果Bean实现BeanNameAware接口,执行setBeanName方法
4、如果Bean实现BeanFactoryAware接口,执行setBeanFactory方法,获取Spring容器
5、如果存在类实现BeanPostProcessor接口(后处理Bean),执行postProcessBeforeInitialization方法
6、如果Bean实现InitializingBean接口,执行afterPropertiesSet方法
7、调用<bean init-method=“init”>指定初始化方法init
8、如果存在类实现BeanPostProcessor接口(处理Bean),执行postProcessAfterInitialization方法
执行业务处理
9、如果Bean实现DisposableBean接口,执行destroy方法
10、调用<bean destroy-method=“customerDestroy”>,指定销毁方法customerDestroy
二、示例代码如下
User.java
package com.zzu.model;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
public clas