BeanFactory 和 ApplicationContext 谁才是 Spring IoC 容器?

    科技2025-11-16  9

    BeanFactory 和 ApplicationContext 谁才是 Spring IoC 容器?

    The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s IoC container. The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object. ApplicationContext is a sub-interface of BeanFactory. It adds:

    Easier integration with Spring’s AOP featuresMessage resource handling (for use in internationalization)Event publicationApplication-layer specific contexts such as the WebApplicationContext for use in web applications.

    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 and is used exclusively in this chapter in descriptions of Spring’s IoC container. For more information on using the BeanFactory instead of the ApplicationContext, see The BeanFactory.

    ClassPathXmlApplicationContext 和 BeanFactory 的继承关系

    ClassPathXmlApplicationContext <- AbstractRefreshableApplicationContext <- ApplicactionContext <- BeanFactory

    ClassPathXmlApplicationContext 和 BeanFacotry 的组合关系

    ClassPathXmlApplicationContext#getBean() = AbstractRefreshableApplicationContext#getBeanFactory()#getBean()

    AbstractRefreshableApplicationContext#getBeanFactory() = DefaultListableBeanFactory <- BeanFactory

    Processed: 0.021, SQL: 8