分析BeanFactoryPostProcessor


分析BeanFactoryPostProcessor

BeanFactoryPostProcessor是在注册完成BeanDifinition后执行的接口,该接口就只有一个方法postProcessBeanFactory

public interface BeanFactoryPostProcessor {
    void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;
}

子类PropertyPlaceholderConfigurer

PropertyPlaceholderConfigurer已过时

PropertyResourceConfigurer帮着处理好属性后传入子类的方法进行执行

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	try {
		Properties mergedProps = mergeProperties();

		// Convert the merged properties, if necessary.
		convertProperties(mergedProps);

		// Let the subclass process the properties.
		processProperties(beanFactory, mergedProps);
	}
	catch (IOException ex) {
		throw new BeanInitializationException("Could not load properties", ex);
	}
}

主要用法是用于不同的环境注入不同的环境参数,在springBoot中可以用envAbstractEnvironment来进行替代


  TOC