Spring框架中的应用程序上下文和bean工厂是什么 [英] What is Application context and bean factory in spring framework

查看:150
本文介绍了Spring框架中的应用程序上下文和bean工厂是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
BeanFactory与ApplicationContext

Possible Duplicate:
BeanFactory vs ApplicationContext

Spring框架中Application context和bean factory的简单含义.

Simple word meaning of Application context and bean factory in spring framework.

推荐答案

BeanFactory

BeanFactory是用于实例化,配置和管理多个Bean的实际容器.这些bean通常相互协作,因此彼此之间具有依赖性.这些依赖关系反映在BeanFactory所使用的配置数据中(尽管某些依赖关系可能不会作为配置数据可见,而是在运行时Bean之间的编程交互作用的函数.)

The BeanFactory is the actual container which instantiates, configures, and manages a number of beans. These beans typically collaborate with one another, and thus have dependencies between themselves. These dependencies are reflected in the configuration data used by the BeanFactory (although some dependencies may not be visible as configuration data, but rather be a function of programmatic interactions between beans at runtime).

ApplicationContext

尽管bean程序包通常以编程方式提供用于管理和操作bean的基本功能,但上下文程序包添加了ApplicationContext,它以更加面向框架的方式增强了BeanFactory功能.许多用户将以完全声明性的方式使用ApplicationContext,甚至不必手动创建它,而是依靠诸如ContextLoader之类的支持类来自动启动ApplicationContext,这是Java EE网络正常启动过程的一部分,应用程序.当然,仍然可以通过编程方式创建ApplicationContext.

While the beans package provides basic functionality for managing and manipulating beans, often in a programmatic way, the context package adds ApplicationContext, which enhances BeanFactory functionality in a more framework-oriented style. Many users will use ApplicationContext in a completely declarative fashion, not even having to create it manually, but instead relying on support classes such as ContextLoader to automatically start an ApplicationContext as part of the normal startup process of a Java EE web-app. Of course, it is still possible to programmatically create an ApplicationContext.

上下文包的基础是位于org.springframework.context包中的ApplicationContext接口.从BeanFactory接口派生,它提供了BeanFactory的所有功能.为了允许使用分层和分层上下文以更加面向框架的方式工作,上下文包还提供以下内容:

The basis for the context package is the ApplicationContext interface, located in the org.springframework.context package. Deriving from the BeanFactory interface, it provides all the functionality of BeanFactory. To allow working in a more framework-oriented fashion, using layering and hierarchical contexts, the context package also provides the following:

  • MessageSource,提供对i18n样式的消息的访问

  • MessageSource, providing access to messages in, i18n-style

访问资源,例如URL和文件

Access to resources, such as URLs and files

事件传播到实现ApplicationListener接口的bean

Event propagation to beans implementing the ApplicationListener interface

加载多个(分层)上下文,允许每个上下文集中在一个特定的层上,例如应用程序的Web层

Loading of multiple (hierarchical) contexts, allowing each to be focused on one particular layer, for example the web layer of an application

由于ApplicationContext包括BeanFactory的所有功能,因此通常建议在BeanFactory上使用它,除了少数有限的情况(例如在applet中),其中内存消耗可能很关键,然后增加几千字节可能会有所不同.以下各节介绍了ApplicationContext添加到基本BeanFactory功能的功能.

As the ApplicationContext includes all functionality of the BeanFactory, it is generally recommended that it be used over the BeanFactory, except for a few limited situations such as perhaps in an applet, where memory consumption might be critical, and a few extra kilobytes might make a difference. The following sections described functionality which ApplicationContext adds to basic BeanFactory capabilities.

http://static.springsource.org/spring/docs/1.2.x/reference/beans.html

这篇关于Spring框架中的应用程序上下文和bean工厂是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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