package com.zxl.spring;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringApp15 {
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("SpringBeans.xml");
context.close();
}
}
package com.zxl.spring;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
public class SpringBean01 implements InitializingBean ,DisposableBean {
@Override
public void afterPropertiesSet() throws Exception {
// TODO Auto-generated method stub
System.out.println("SpringBean01.afterPropertiesSet()...");;
}
@Override
public void destroy() throws Exception {
// TODO Auto-generated method stub
System.out.println("SpringBean01.destroy()...");
}
}
package com.zxl.spring;
public class SpringBean02 {
}
package com.zxl.spring;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
public class SpringContainerBean implements DestructionAwareBeanPostProcessor {
@Override
public void postProcessBeforeDestruction(Object springBean, String springBeanName) throws BeansException {
// TODO Auto-generated method stub
System.out.println("SpringContainerBean.postProcessBeforeDestruction-->"+
"Bean_Class_Name = "+springBean.getClass().getSimpleName()+" and bean_name = "+springBeanName);
}
@Override
public Object postProcessAfterInitialization(Object springBean, String springBeanName) throws BeansException {
// TODO Auto-generated method stub
System.out.println("SpringContainerBean.postProcessAfterInitialization-->"+
"Bean_Class_Name = "+springBean.getClass().getSimpleName()+" and bean_name = "+springBeanName);
System.out.println("------------------");
return springBean;
}
@Override
public Object postProcessBeforeInitialization(Object springBean, String springBeanName) throws BeansException {
// TODO Auto-generated method stub
System.out.println("SpringContainerBean.postProcessBeforeInitialization-->"+
"Bean_Class_Name = "+springBean.getClass().getSimpleName()+" and bean_name = "+springBeanName);
return springBean;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" >
<bean id="springContainerBean" class="com.zxl.spring.SpringContainerBean"/>
<bean id="springBean01" class="com.zxl.spring.SpringBean01"/>
<bean id="springBean02" class="com.zxl.spring.SpringBean02"/>
</beans>