且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建beanfactory对象有哪些不同的方法?

更新时间:2023-12-04 19:30:16

ApplicationContext派生自BeanFactory接口,因此它具有BeanFactory所具有的所有功能,还有额外的功能,下面是Spring官方网站:
MessageSource,提供对i18n风格的消息的访问。
访问资源,例如URL和文件。
事件传播到实现ApplicationListener接口的bean。
加载多个(分层)上下文,允许每个上下文集中于一个特定的上下文图层,例如应用程序的Web图层。

The ApplicationContext is derived from BeanFactory interface, so it has all the functions that BeanFactory has and also has extra functions, below part is in Spring official website: MessageSource, providing access to messages in i18n-style. Access to resources, such as URLs and files. Event propagation to beans implementing the ApplicationListener interface. Loading of multiple (hierarchical) contexts, allowing each to be focused on one particular layer, for example the web layer of an application.

正如您所说的一些代码使用BeanFactory而某些代码使用ApplicationContext,它实际上没有什么不同,但是1,因为ApplicationContext的额外功能,它会更加繁重,可以与事务和aop 一起使用,在容器环境中使用它会非常好,例如Tomcat等。
你可以在这里找到更多,尤其是第3.8.1节。 BeanFactory或ApplicationContext? http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#context-introduction-ctx-vs-beanfactory

As you said that some code uses BeanFactory and some uses ApplicationContext, it's actually no more different, but 1 thing, because of the extra functions of ApplicationContext,it will be more heavy and can work with transaction and aop, it will be very good to used in the container environment, such as Tomcat and others. You can find more in here, especially sec 3.8.1. BeanFactory or ApplicationContext?: http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#context-introduction-ctx-vs-beanfactory