Spring便利工厂Bean与测试策略详解
1. Spring便利工厂Bean
Spring包含一些尚未介绍的工厂Bean,这些工厂Bean能让某些容器配置更简单,甚至成为可能。不过,当Spring在应用上下文中实现内置表达式语言支持(计划在Spring 1.3完成)后,这些工厂Bean的实用性会降低。
1.1 PropertyPathFactoryBean
PropertyPathFactoryBean是一个非常实用的工厂Bean,可用于返回对目标对象的属性路径求值的结果。当需要获取某个Bean的属性或属性的属性时,它能发挥作用。以下是一些示例:
<bean id="person"
...
</bean>
<bean id="theCity"
class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
<property name="targetObject"><ref local="person"/></property>
<property name="propertyPath"><value>address.city</value></property>
</bean>
上述示例中,工厂Bean的结果是所指向的 person
Bean的 address
属