You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
source-code-hunter/docs/Spring/IoC/BeanPostProcessor.md

18 lines
858 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

BeanPostProcessor接口 也叫 Bean后置处理器作用是在Bean对象实例化和依赖注入完成后在显示调用bean的init-method(初始化方法)的前后添加我们自己的处理逻辑。注意是Bean实例化完毕后及依赖注入完成后触发的接口的源码如下。
```java
public interface BeanPostProcessor {
/**
* 实例化、依赖注入完毕,
* 在调用显示的初始化之前完成一些定制的初始化任务
*/
Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;
/**
* 实例化、依赖注入、初始化完毕时执行
*/
Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;
}
```
使用方法也很简单,实现 BeanPostProcessor接口然后将实现类注入IoC容器即可。