BeanFactory vs ApplicationContext关注BeanPostProcessor和BeanFactoryPostProcessor

发布于 2025-02-01 08:32:06 字数 731 浏览 4 评论 0 原文

现在,我正在学习有关春季IOC容器的一些细节,其中BeanFactory与应用程序上下文之间的差异。 链接中引用了以前的堆栈溢出讨论和教程点

我还从以下 href =“ https://www.tutorialspoint.com/spring/spring_ioc_containers.htm” rel =“ nofollow noreferrer”> https://www.tutorialspoint.com/spring/spring/spring_ioc_containers.ioc_containers.htm

该ApplicationContext能够从属性文件中解析文本消息,以及将应用程序事件发布给感兴趣的事件听众

注册和BeanFactoryPostProcessor注册的

  1. BeanPostProcessor 能力手动执行BeanPostProcessor注册,这是否意味着开发人员在启动Bean时正在做某事?因为,相同的流程应用程序context会根据文档自动

    自动。
  2. beanfactorypostprocessor注册的目的是什么? BeanPostProcessor和BeanFactoryPostProcessor有什么区别?

  3. 如果我们说applicationContext能够从属性文件(消息源访问)解决文本消息,那么应用程序上下文与属性文件进行通信?

我如何更好地理解这个概念?

I am now learning little bit detail about Spring IoC Containers with the difference between BeanFactory Vs Application Context. I was also referring the previous stack overflow discussion and tutorial point from the following links,

BeanFactory vs ApplicationContext

https://www.tutorialspoint.com/spring/spring_ioc_containers.htm

In my learning I found that ApplicationContext is capable of resolving textual messages from a properties file and the ability to publish application events to interested event listeners

And BeanPostProcessor Registration and BeanFactoryPostProcessor Registration doing manually in BeanFactory and automatically doing in application context,

So my confusions are,

  1. Since BeanFactory Manually doing BeanPostProcessor registration, Does that mean the developer is doing something while bean is getting initiating ? Because, the same process ApplicationContext does automaticall according to documentations

  2. What is the purpose of BeanFactoryPostProcessor registration ? What is the difference between BeanPostProcessor and BeanFactoryPostProcessor ?

  3. If we say ApplicationContext has the ability to resolving text messages from properties file (Message source access), So for what purpose application context is communicating with property file ?

How can I better understand this concept ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2025-02-08 08:32:06
  1. beanFactory轻量级,并且不会加载内存/初始化application.xml(甚至是单身bean)的任何bean。而ApplicationContext是重量级,将所有内容都加载到容器启动上。 BeanFactory还支持诸如Proto和Singleton之类的有限范围,并且AOP之类的功能与BeanFactory无法使用。
    ,要回答您的第一个问题是的,在使用beanFactory时,仅加载XML并创建BeanFactory对象,就不能保证任何Bean是初始化的;唯一使用它的地方是当您关注运行时内存消耗
    注意:ApplicationContext扩展了ListableBeanFactory扩展了BeanFactory。

  2. beanpostProcessor的名称为您提供钩子,可以在applciationContext/ beanfactory实现(即初始化之前和之后)春季aops之类的交易。 caching etc. ref

  3. ApplicationContext主要责任是BEAN的初始化,现在根据单个BEAN的定义,它提供了执行专业任务(例如Resources Bundle Bundle Loading/property Configurer)的方式。我建议您查看javadoc,以实现应用程序context,例如

  1. BeanFactory is lightweight and it doesn't load in-memory/initialize any bean from application.xml (even singleton beans) unless factory.getBean("bean-name") method is called; whereas ApplicationContext is heavyweight is loads everything on container startup. BeanFactory also supports limited scopes like proto and singleton and features like AOP doesn't work with BeanFactory.
    So to answer your 1st question YES while using BeanFactory just loading the xml and creating BeanFactory object does not guarantee any bean is initialized; only place to use it is when you are concerned of runtime memory consumption
    Note: ApplicationContext extends ListableBeanFactory extends BeanFactory.

  2. BeanPostProcessor as the name suggest gives you hooks to work on an instance of a bean created by the spring container by ApplciationContext/BeanFactory implementation (i.e. before and after initialization) Spring AOPs like transactions. caching etc. ref @Required for example. BeanFactoryPostProcessor on the other end lets you modify the actual bean definition before initialization of the instance. The PropertyResourceConfigurer and PropertyPlaceholderConfigurer are two good examples refer PropertyResourceConfigurer example, how properties are changed before initializing the actual beans.

  3. ApplicationContext main responsibility is initialization of bean, now based on the individual bean is defined it provides way to perform specialized tasks like resources bundle loading/property configurer. I suggest you look at the javadoc for a concrete implementation of ApplicationContext like GenericApplicationContext . If you look at how each methods are implemented you will understand how the control flows from AppContext to individual beans before and after they are initialized. AppContext only has the contract for supports tasks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文