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.3.1.1Aliasing a Bean outside the Bean Definition 在Bean定义外指定Bean别名
1.3.2. Instantiating Beans实例化bean
1.3.2.1.Instantiation with a Constructor (通过构造函数进行实例化)
1.3.2.2. Instantiation with a Static Factory Method (通过静态工厂方法进行实例化)
1.3.2.3. Instantiation by Using an Instance Factory Method (使用实例工厂方法进行实例化)
1.3.2.4. Determining a Bean’s Runtime Type(确定Bean的运行时类型)
下载此文档精编完整版
No. | 内容 | 下载地址 | 文档内容目录 |
1 | 中英双语精编版 第一部分 | PDF下载 | 内容目录 |
2 | 中英双语精编版 第二部分 | PDF下载 | 内容目录 |
3 | 中文精编版 第一部分 | PDF下载 | 内容目录 |
4 | 中文精编版 第二部分 | PDF下载 | 内容目录 |
更多章节内容,请点击查看: Core Technologies
1.3.2.4. Determining a Bean’s Runtime Type(确定Bean的运行时类型)
The runtime type of a specific bean is non-trivial to determine. A specified class in the bean metadata definition is just an initial class reference, potentially combined with a declared factory method or being a FactoryBean
class which may lead to a different runtime type of the bean, or not being set at all in case of an instance-level factory method (which is resolved via the specified factory-bean
name instead). Additionally, AOP proxying may wrap a bean instance with an interface-based proxy with limited exposure of the target bean’s actual type (just its implemented interfaces).
特定bean的运行时类型很难确定。Bean元数据定义中的指定类(class)只是一个初始类引用(initial class reference),可能与声明的工厂方法组合,或者是一个FactoryBean
类,这可能导致不同的bean运行时类型,或者在实例级工厂方法的情况下根本不设置(而是通过指定的factory-bean
名称来解析)。此外,AOP代理可以使用基于接口的代理来包装一个bean实例,并有限地公开目标bean的实际类型(仅其实现的接口)。
The recommended way to find out about the actual runtime type of a particular bean is a BeanFactory.getType
call for the specified bean name. This takes all of the above cases into account and returns the type of object that a BeanFactory.getBean
call is going to return for the same bean name.
寻找特定bean的实际运行时类型的推荐方法是对指定bean名称进行BeanFactory.getType
调用。这将考虑上述所有情况,并返回为相同的bean名称调用BeanFactory.getBean
时将返回的对象类型。