Spring Framework Documentation (5.3.10)
Core | IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP. |
1. The IoC Container
1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)
1.2. Container Overview (容器概览)
1.4.1. Dependency Injection(依赖注入)
1.4.1.1. Constructor-based Dependency Injection(基于构造函数的依赖注入) (Part I)
1.4.1.1. Constructor-based Dependency Injection(基于构造函数的依赖注入) (Part II)
1.4.1.2.Setter-based Dependency Injection(基于Setter的依赖注入)
1.4.1.3.Dependency Resolution Process(依赖解析过程)
1.4.1.4. Examples of Dependency Injection(依赖注入示例)
1.4.2. Dependencies and Configuration in Detail(依赖与配置详细介绍)
1.4.3. Using depends-on(使用depends-on)
1.4.4. Lazy-initialized Beans(延迟初始化Bean)
1.4.5. Autowiring Collaborators(自动装配协作者)
1.4.6.1. Lookup Method Injection(查找方法注入)
1.4.6.2. Arbitrary Method Replacement(任意方法替换)
下载此文档精编完整版
No. | 内容 | 下载地址 | 文档内容目录 |
1 | 中英双语精编版 第一部分 | PDF下载 | 内容目录 |
2 | 中英双语精编版 第二部分 | PDF下载 | 内容目录 |
3 | 中文精编版 第一部分 | PDF下载 | 内容目录 |
4 | 中文精编版 第二部分 | PDF下载 | 内容目录 |
更多章节内容,请点击查看: Core Technologies
1.4.3. Using depends-on(
使用
depends-on)
If a bean is a dependency of another bean, that usually means that one bean is set as a property of another. Typically you accomplish this with the <ref/> element in XML-based configuration metadata. However, sometimes dependencies between beans are less direct. An example is when a static initializer in a class needs to be triggered, such as for database driver registration. The depends-on
attribute can explicitly force one or more beans to be initialized before the bean using this element is initialized. The following example uses the depends-on
attribute to express a dependency on a single bean:
如果一个bean是另一个bean的依赖项,这通常意味着一个bean被设置为另一个bean的属性(property)。通常,您可以通过基于XML的配置元数据中的<ref/>元素(element)来实现这一点。然而,有时候bean之间的依赖关系不那么直接。例如,需要触发类中的静态初始化方法,例如数据库驱动程序注册。在使用该元素的bean被初始化之前,depends-on
属性可以显式地强制一个或多个bean被初始化。以下示例使用 depends-on
属性表示对单个bean的依赖关系:
<bean id="beanOne" class="ExampleBean" depends-on="manager"/>
<bean id="manager" class="ManagerBean" />
To express a dependency on multiple beans, supply a list of bean names as the value of the depends-on
attribute (commas, whitespace, and semicolons are valid delimiters):
要表示对多个bean的依赖关系,请提供一个bean名称列表作为depends-on
属性的值(逗号、空格和分号是有效的分隔符):
<bean id="beanOne" class="ExampleBean" depends-on="manager,accountDao">
<property name="manager" ref="manager" />
</bean>
<bean id="manager" class="ManagerBean" />
<bean id="accountDao" class="x.y.jdbc.JdbcAccountDao" />
| The |
|
|