org.springframework.context.support
Class ClassPathXmlApplicationContext
java.lang.Objectorg.springframework.core.io.DefaultResourceLoaderorg.springframework.context.support.AbstractApplicationContextorg.springframework.context.support.AbstractRefreshableApplicationContextorg.springframework.context.support.AbstractRefreshableConfigApplicationContextorg.springframework.context.support.AbstractXmlApplicationContextorg.springframework.context.support.ClassPathXmlApplicationContext
- All Implemented Interfaces:
- BeanFactory, BeanNameAware, DisposableBean, HierarchicalBeanFactory, InitializingBean, ListableBeanFactory, ApplicationContext, ApplicationEventPublisher,ConfigurableApplicationContext, Lifecycle, MessageSource, ResourceLoader, ResourcePatternResolver
-
public class ClassPathXmlApplicationContext
- extends AbstractXmlApplicationContext
该类继承了AbstractXmlApplicationContext,实现了BeanFctory和ApplicationContext接口。
使用BeanFactory接口还是ApplicationContext接口?
BeanFactory只是实现了Spring基本的功能,而ApplicationContext添加了更多的功能,并且ApplicationContext完全支持BeanFactory的所有功能,ApplicationContext建立于BeanFactory基础之上的。ApplicationContext是BeanFactory的子接口,而BeanFactory是ApplicationContext的父接口。所以,建议优先使用ApplicationContext接口。
官方文档解释:
In short, the BeanFactory
provides the configuration framework and basic functionality, and the ApplicationContext
adds more enterprise-specific functionality. The ApplicationContext
is a complete superset of the BeanFactory
时间: 2024-10-22 08:32:16