实际应用中,某个实例的属性可能是另一个对象的一个属性,Spring支持将bean实例的属性值直接赋值给一个变量
属性值的注入,是通过PropertyPathFactoryBean完成的,PropertyPathFactoryBean用来获取目标bean的属性,获得的值可以注入到其他bean,也可以定义成新的bean
实体类:


































配置文件:提供四种注入























<
bean
id
="person.son.age"
class
="org.springframework.beans.factory.config.PropertyPathFactoryBean"
/>
</
property
>
</
bean
>
<!--
以下将会获得结果son,它将是person bean的son的数值
-->
<
bean
id
="son2"
class
="org.springframework.beans.factory.config.PropertyPathFactoryBean"
>
<
property
name
="targetBeanName"
>
<
value
>
person
</
value
>
</
property
>
<
property
name
="propertyPath"
>
<
value
>
son
</
value
>
</
property
>
</
bean
>
<!--
以下将会获得结果16,它将是person bean的son的age属性
-->
<
bean
id
="son3"
class
="org.springframework.beans.factory.config.PropertyPathFactoryBean"
>
<
property
name
="targetBeanName"
>
<
value
>
person
</
value
>
</
property
>
<
property
name
="propertyPath"
>
<
value
>
son.age
</
value
>
</
property
>
</
bean
>
<!--
以下会获得结果为30 ,它将是获得该bean的内部bean的age属性
-->
<
bean
id
="son4"
class
="org.springframework.beans.factory.config.PropertyPathFactoryBean"
>
<
property
name
="targetObject"
>
<
bean
class
="Bean.superIOCparam.Person"
>
<
property
name
="age"
><
value
>
30
</
value
></
property
>
</
bean
>
</
property
>
<
property
name
="propertyPath"
><
value
>
age
</
value
></
property
>
</
bean
>
</
beans
>

































测试代码:














运行结果:
person age is:16
person age is:16
16
30