Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanPostProcessor和BeanFactoryPostProcessor区别 #3

Open
Thw841277862 opened this issue Oct 16, 2023 · 1 comment
Open

BeanPostProcessor和BeanFactoryPostProcessor区别 #3

Thw841277862 opened this issue Oct 16, 2023 · 1 comment
Labels
question Further information is requested

Comments

@Thw841277862
Copy link

作者你好,我看了你对BeanPostProcessor和BeanFactoryPostProcessor源码分析。都似乎在做一些与bean相关的操作。我想知道这两者具体有什么不同。

@xuchengsheng
Copy link
Owner

它们之间的主要区别有:

操作时机
BeanFactoryPostProcessor是在Spring容器加载了bean的定义之后,但在bean实例化之前被调用的而BeanPostProcessor是在Spring容器实例化bean之后,且在bean的初始化方法之前和之后进行调用的。

操作对象
BeanFactoryPostProcessor操作的是bean的定义。它允许你修改bean的定义属性,例如可以改变bean的作用域,属性值等,而BeanPostProcessor操作的是bean的实例。它允许你在实例化后、初始化前后对bean实例进行某些操作。

使用场景
BeanFactoryPostProcessor通常用于修改bean的定义。而BeanPostProcessor通常用于修改新创建的bean实例。

执行顺序
BeanFactoryPostProcessor会按照优先级和顺序进行排序调用,而BeanPostProcessor则会按照它们在容器中的定义顺序进行调用。

@xuchengsheng xuchengsheng added the question Further information is requested label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants