實(shí)際應(yīng)用中,某個(gè)實(shí)例的屬性可能是另一個(gè)對(duì)象的一個(gè)屬性,Spring支持將bean實(shí)例的屬性值直接賦值給一個(gè)變量
屬性值的注入,是通過PropertyPathFactoryBean完成的,PropertyPathFactoryBean用來獲取目標(biāo)bean的屬性,獲得的值可以注入到其他bean,也可以定義成新的bean
實(shí)體類:


































配置文件:提供四種注入























<bean id="person.son.age" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
</property>
</bean>
<!-- 以下將會(huì)獲得結(jié)果son,它將是person bean的son的數(shù)值-->
<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>
<!-- 以下將會(huì)獲得結(jié)果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>
<!-- 以下會(huì)獲得結(jié)果為30 ,它將是獲得該bean的內(nèi)部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>

































測(cè)試代碼:














運(yùn)行結(jié)果:
person age is:16
person age is:16
16
30