在BeanFactory加载Bean定义档的所有内容,但还没正式产生Bean实例之前,您可以对该BeanFactory进行一些处理,您只要实现 org.springframework.beans.factory.config.BeanFactoryPostProcessor:
package org.springframework.beans.factory.config;
public interface BeanFactoryPostProcessor {
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) throws BeansException;
}
假设您有一个SomClass实现了BeanFactoryPostProcessor,则您可以在Bean定义档中定义它:
....
<beans>
<bean id="beanFactoryModifier" class="onlyfun.caterpillar.SomeClass"/>
<bean id="helloBean" class="onlyfun.caterpillar.HelloBean">
....
</beans>
使用ApplicationContext时,若Bean定义档中有定义实现BeanFactoryPostProcessor的类别,则ApplicationContext会自动应用。
在Spring中有几个BeanFactoryPostProcessor的实现实例,像是:
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer org.springframework.beans.factory.config.PropertyOverrideConfigurer org.springframework.beans.factory.config.CustomEditorConfigurer