Spring IOC之后置处理器分析(四)

一、BeanPostProcessor

Bean的后置处理器,主要在bean初始化前后工作。

public interface BeanPostProcessor {
	// 在初始化方法(如:afterPropertiesSet 或 init-method)执行前触发
	Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;

	// 在初始化方法(如:afterPropertiesSet 或 init-method)执行后触发
	Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;
}

二、InstantiationAwareBeanPostProcessor

InstantiationAwareBeanPostProcessor继承于BeanPostProcessor,主要在实例化Bean前后工作; AOP创建代理对象就是通过该接口实现。

public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
	// 对象实例化前
	Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException;

	// 对象实例化后
	boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException;

	PropertyValues postProcessPropertyValues(
			PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException;
}

三、BeanFactoryPostProcessor

Bean工厂的后置处理器,在Bean定义(BeanDefinition)加载完成后,Bean尚未初始化前执行。

public interface BeanFactoryPostProcessor {
	/**
	 * Modify the application context's internal bean factory after its standard
	 * initialization. All bean definitions will have been loaded, but no beans
	 * will have been instantiated yet. This allows for overriding or adding
	 * properties even to eager-initializing beans.
	 * @param beanFactory the bean factory used by the application context
	 * @throws org.springframework.beans.BeansException in case of errors
	 */
	void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;
}

四、BeanDefinitionRegistryPostProcessor

BeanDefinitionRegistryPostProcessor继承于BeanFactoryPostProcessor。其自定义的方法postProcessBeanDefinitionRegistry会在Bean定义(BeanDefinition)将要加载,Bean尚未初始化前真执行,即在BeanFactoryPostProcessor的postProcessBeanFactory方法前被调用。

public interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor {
	/**
	 * Modify the application context's internal bean definition registry after its
	 * standard initialization. All regular bean definitions will have been loaded,
	 * but no beans will have been instantiated yet. This allows for adding further
	 * bean definitions before the next post-processing phase kicks in.
	 * @param registry the bean definition registry used by the application context
	 * @throws org.springframework.beans.BeansException in case of errors
	 */
	void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值