生命周期
构造 ---》set---》Bean
init前后执行 (新创建 类)
public class MyBeanPostProcesser implements BeanPostProcessor{//在init方法之前执行//Object bean: 当前正在初始化的bean对象//String beanName:当前正在初始化的bean的id值.@Overridepublic Object postProcessBeforeInitialization(Object bean, String beanName)throws BeansException {System.out.println("postProcessBeforeInitialization "+beanName); }
//做一些校验的工作 校验数据的合法性等.
//因为是通过Car类来演示的,因此就直接强转了.//if(bean instanceof XXX)Car car = (Car)bean ;car.setPrice(450000);return bean;}
//在init方法之后执行
@Overridepublic Object postProcessAfterInitialization(Object bean, String beanName)throws BeansException {System.out.println("postProcessAfterInitialization "+ beanName);Car car = new Car();car.setBrand("bmw");car.setPrice(100000);return car;}}