这是 Spring Framework 对 ApplicationContext 的解释:- The org.springframework.context.ApplicationContext interface represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the beans.
复制代码 ApplicationContext 代表 Spring 的 IOC 容器,负责实例化、配置和组装 bean。
Spring Framework 把 ApplicationContext 称为容器,其实不是太精确,真正的容器应该是 org.springframework.beans.factory.BeanFactory,不过 ApplicationContext 是 BeanFactory 的子接口,并提供 AutowireCapableBeanFactory 的引用,如许 ApplicationContext 就拥有了 Bean 读取和装载的本领,因此,一般也笼统的称 ApplicationContext 为容器。
再回到区别上来,这是 Spring Framework 的描述:- In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality.
复制代码- public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory,
- MessageSource, ApplicationEventPublisher, ResourcePatternResolver {
- }
复制代码 可以看到 ApplicationContext 还扩展了其它接口,提供了其它功能:
- 通过 MessageSource 提供 i18n 国际化支持;
- 通过 ResourceLoader 提供资源的加载,比如 class path 或体系资源;
- 通过 ApplicationEventPublisher 对实现了 ApplicationListener 的 bean 进行事件通知;
- 通过 HierarchicalBeanFactory 加载多个上下文;
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |