BeanFactoryPostProcessor


在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