原文链接:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans
1. The IoC Container
1.1. Introduction to the Spring IoC Container and Beans
IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies (that is, the other objects they work with) only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method.The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse (hence the name, Inversion of Control) of the bean itself controlling the instantiation or location of its dependencies by using direct construction of classes or a mechanism such as the Service Locator pattern.
IoC 也称为依赖注入 (DI)。这是一个过程,其中对象仅通过构造函数参数、工厂方法的参数或在对象实例被构造或从工厂方法返回后在对象实例上设置的属性来定义它们的依赖项(即,它们使用的其他对象)。然后容器在创建 bean 时注入这些依赖项。这个过程基本上是 bean 本身的逆过程(因此得名,控制反转),通过使用类的直接构造或诸如服务定位器模式之类的机制来控制其依赖项的实例化或位置。
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:
org.springframework.beans 和 org.springframework.context 包是Spring框架的IoC容器的基础。BeanFactory接口提供了一种能够管理任何类型对象的高级配置机制。ApplicationContext 是 BeanFactory 的子接口。它增加了:
-
Easier integration with Spring’s AOP features
更容易与 Spring 的 AOP 特性集成 -
Message resource handling (for use in internationalization)
消息资源处理(用于国际化) -
Event publication
事件发布 -
Application-layer specific contexts such as the WebApplicationContext for use in web applications.
应用层特定的上下文,例如 WebApplicationContext 在 Web 应用程序中使用。
In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality.
简而言之,BeanFactory 提供了配置框架和基本功能,ApplicationContext 增加了更多企业特定的功能。