private String content;
public HelloDaoImpl() {
System.out.println("----------HelloDaoImpl实例化");
}
public void setContent(String content) {
System.out.println("----------通过依赖注入的内容是:" + content);
this.content = content;
}
@Override
public void setBeanName(String beanId) {
System.out.println("----------输出BeanId:" + beanId);
}
@Override
public void setBeanFactory(BeanFactory factory) throws BeansException {
System.out.println("----------factory:" + factory.getClass());
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
System.out.println("----------" + applicationContext);
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("----------afterPropertiesSet");
}
public void init() {
System.out.println("----------初始化方法");
}
@Override
public void destroy() throws Exception {
System.out.println("----------bean被销毁");
}
public void close() {
System.out.println("----------close");
}
}
package www.csdn.spring.dao;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class HelloDaoImpl implements BeanNameAware, BeanFactoryAware,
InitializingBean, ApplicationContextAware, DisposableBean {
private String content;
public HelloDaoImpl() {
System.out.println("----------HelloDaoImpl实例化");
}
public void setContent(String content) {
System.out.println("----------通过依赖注入的内容是:" + content);
this.content = content;
}
@Override
public void setBeanName(String beanId) {
System.out.println("----------输出BeanId:" + beanId);
}
@Override
public void setBeanFactory(BeanFactory factory) throws BeansException {
System.out.println("----------factory:" + factory.getClass());
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
System.out.println("----------" + applicationContext);
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("----------afterPropertiesSet");
}
public void init() {
System.out.println("----------初始化方法");
}
@Override
public void destroy() throws Exception {
System.out.println("----------bean被销毁");
}
public void close() {
System.out.println("----------close");
}
}
创建BeanPostProcessor实现类
[java]
package www.csdn.spring.dao;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
public class BeanPostProcessorImpl implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
System.out.println("我把:" + beanName + "实例化化之前的操作");
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean,