Spring中BeanFactory与ApplicationContext的区别

BeanFactory:Bean工厂接口,是访问Spring Bean容器的根接口,基本Bean视图客户端。从其名称上即可看出其功能,即实现Spring Bean容器的读取。

ApplicationContext:一个应用配置的中心接口,提供以下功能:

1.Bean factory methods for accessing application components,Inherited from {@link org.springframework.beans.factory.ListableBeanFactory}.(Bean工厂访问应用组件方法)

2.The ability to load file resources in a generic fashion.Inherited from the {@link org.springframework.core.io.ResourceLoader} interface.(以通用方式加载文件资源的能力)

3.The ability to publish events to registered listeners.Inherited from the {@link ApplicationEventPublisher} interface.(可以发布事件到注册监听器上的能力)

4.The ability to resolve messages, supporting internationalization.Inherited from the {@link MessageSource} interface.(处理消息的能力,支持国际化)

5.Inheritance from a parent context. Definitions in a descendant context will always take priority. This means, for example, that a single parent

   context can be used by an entire web application, while each servlet has its own child context that is independent of that of any other servlet.

   (可以继承一个上下文,定义一个派生上下文优先,例如,一个父上下文可以被整个网络应用,然而每一个servlet都有自己独立的子上下文。)

diagram

总结:举个简单的例子:整个应用比作一家企业的话,BeanFactory负责生产主管,而ApplicationContext则是CEO,总览全局,当然也包括生产主管BeanFactory。

猜你喜欢

转载自www.cnblogs.com/jdktomcat/p/9178851.html