實際應用中,某個實例的屬性可能是另一個對象的一個屬性,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