BeanFactoryPostProcessor Interface Overview
Spring container before initialization, allows to define custom extension we change the bean, BeanFactoryPostProcessor just to meet our requirements, postProcessBeanFactory BeanFactoryPostProcessor interface method, we can modify the bean definition information, such as modifying the value of the property, the scope is modified bean single or multiple cases of embodiment.
BeanFactoryPostProcessor
bean plant bean attribute processing vessel, said some of the popular is the ability to manage all beandefinition within our bean plant (not instantiated) data, modify the properties can be arbitrary.
Instructions:
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
AbstractBeanDefinition abstractBeanDefinition = (AbstractBeanDefinition) beanFactory.getBeanDefinition("userService");
MutablePropertyValues pv = abstractBeanDefinition.getPropertyValues();
pv.addPropertyValue("desc", "Desc is changed from bean factory post processor");
abstractBeanDefinition.setScope(BeanDefinition.SCOPE_SINGLETON);
}
}
Details BeanFactoryPostProcessor refer spring4.1.8 extended combat five: changing the definition of the bean (BeanFactoryPostProcessor Interface)