BeanFactoryPostProcessor(Bean工厂后处理器)

在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;
}


假设您有一个类MyClass实例了BeanFactoryPostProcessor,则您可以在Bean定义档中定义它:


....
<beans>
<bean id="beanFactoryModifier"
class="onlyfun.caterpillar.SomeClass"/>
....
</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。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章