BeanFactory与ApplicationContext [英] BeanFactory vs ApplicationContext

查看:109
本文介绍了BeanFactory与ApplicationContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Spring Framework还是很陌生,我一直在使用它,并将一些示例应用程序放在一起,以评估Spring MVC以便在即将到来的公司项目中使用.到目前为止,我非常喜欢在Spring MVC中看到的内容,它似乎非常易于使用,并鼓励您编写对单元测试非常友好的类.

I'm pretty new to the Spring Framework, I've been playing around with it and putting a few samples apps together for the purposes of evaluating Spring MVC for use in an upcoming company project. So far I really like what I see in Spring MVC, seems very easy to use and encourages you to write classes that are very unit test-friendly.

作为练习,我正在为我的一个样本/测试项目编写一种主要方法.我不清楚的一件事是BeanFactoryApplicationContext之间的确切区别-适用于哪种条件?

Just as an exercise, I'm writing a main method for one of my sample/test projects. One thing I'm unclear about is the exact differences between BeanFactory and ApplicationContext - which is appropriate to use in which conditions?

我知道ApplicationContextBeanFactory的扩展,但是如果我只是写一个简单的main方法,我是否需要ApplicationContext提供的额外功能?究竟ApplicationContext提供了什么样的额外功能?

I understand that ApplicationContext extends BeanFactory, but if I'm just writing a simple main method, do I need the extra functionality that ApplicationContext provides? And just exactly what kind of extra functionality does ApplicationContext provide?

除了回答我应该在main()方法中使用哪个"之外,在这种情况下我应该使用哪种实现还有任何标准或准则?应该将main()方法编写为依赖于XML格式的Bean/应用程序配置-这是一个安全的假设,还是我将用户锁定在特定的位置?

In addition to answering "which should I use in a main() method", are there any standards or guidelines as far as which implementation I should use in such a scenario? Should my main() method be written to depend on the bean/application configuration to be in XML format - is that a safe assumption, or am I locking the user into something specific?

这个答案在网络环境中是否会发生变化-如果我的任何一个类需要了解Spring,那么他们是否更有可能需要ApplicationContext?

And does this answer change in a web environment - if any of my classes needed to be aware of Spring, are they more likely to need ApplicationContext?

感谢您的帮助.我知道参考手册中可能会回答很多这样的问题,但是我很难找到这两个接口以及每个接口的优缺点的清晰细目,而没有用细齿梳子通读手册.

Thanks for any help. I know a lot of these questions are probably answered in the reference manual, but I'm having a hard time finding a clear breakdown of these two interfaces and the pros/cons of each without reading thru the manual with a fine-tooth comb.

推荐答案

spring文档在此方面很出色:

The spring docs are great on this: 3.8.1. BeanFactory or ApplicationContext?. They have a table with a comparison, I'll post a snippet:

Bean Factory

  • Bean实例化/接线

应用上下文

  • Bean实例化/接线
  • 自动BeanPostProcessor注册
  • 自动BeanFactoryPostProcessor注册
  • 方便的MessageSource访问(适用于i18n)
  • ApplicationEvent发布

因此,如果您需要在应用程序上下文"侧显示的任何要点,则应使用ApplicationContext.

So if you need any of the points presented on the Application Context side, you should use ApplicationContext.

这篇关于BeanFactory与ApplicationContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆