From d0ec1d342f768cec1608a74700c0fe07547771aa Mon Sep 17 00:00:00 2001 From: AmyliaY <471816751@qq.com> Date: Tue, 28 Jul 2020 23:01:30 +0800 Subject: [PATCH] =?UTF-8?q?Spring=20IoC=E5=AE=B9=E5=99=A8=E4=B9=8B=20BeanP?= =?UTF-8?q?ostProcessor=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + docs/Spring/IoC/BeanPostProcessor.md | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 docs/Spring/IoC/BeanPostProcessor.md diff --git a/README.md b/README.md index 7576584..0a6d9be 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ * [将 bean 解析封装成 BeanDefinition](/docs/Spring/IoC/2、将bean解析封装成BeanDefinition.md) * [将 BeanDefinition 注册进 IoC 容器](/docs/Spring/IoC/3、将BeanDefinition注册进IoC容器.md) * [依赖注入(DI)](/docs/Spring/IoC/4、依赖注入(DI).md) +* [BeanPostProcessor](/docs/Spring/IoC/BeanPostProcessor.md) ### AOP diff --git a/docs/Spring/IoC/BeanPostProcessor.md b/docs/Spring/IoC/BeanPostProcessor.md new file mode 100644 index 0000000..68feca4 --- /dev/null +++ b/docs/Spring/IoC/BeanPostProcessor.md @@ -0,0 +1,18 @@ +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容器即可。 \ No newline at end of file