Spring: BeanFactoryPostProcessor(容器后处理器)的定义

1.定义类实现BeanFactoryPostProcessor接口

package cn.edu.tju;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("this is my beanFactoryPostProcessor...");
	}
}

2.在配置文件中定义上述类的bean

	<bean class="cn.edu.tju.MyBeanFactoryPostProcessor"/>

容器启动时会调用postProcessBeanFactory方法:
在这里插入图片描述

你可能感兴趣的:(Spring,java)