我有以下情况。从外部bean注入bean属性
我有两个豆类,例如:
<bean id="service1" parent="txProxyTemplate">
<property name="target">
<bean autowire="byName" class="Class1"/>
</property>
</bean>
<bean name="manager1" parent="txProxyServiceTemplate">
<property name="target">
<bean autowire="byName" class="ManagerClass1"/
</property>
</bean>
,我有三豆这是真正注入到这两个baens:
<bean name="supportBean" parent="txProxyServiceTemplate">
<property name="target">
<bean autowire="byName" class="SupportBeanClass">
</bean>
</property>
</bean>
有豆类服务1串“路径”栏(path =“第一路径”)和manager1(path =“第二路径”)。 当supportBean被注入到service1和manager1时,我希望supportBean中的某些字符串字段(例如“actualPath”)是从两个封闭的bean自动启动的。春天我怎么能做到这一点?
PS:我需要的服务1和manager1具有supportBean有两个不同的字段(Service1类supportBean有actualPath = “第一路”,在manager1类supportBean有actualPath =“第二条路径)
我希望你明白我,谢谢!
这是相当不错的变体,谢谢:) 但我怎么能避免通过setter设置“路径”?我能通过构造函数以某种方式做到这一点吗? – Dedyshka
@Dedyshka - 您可以使用构造函数注入来自动装载服务。如果你的意思是可以通过它的构造函数在'SupportBean'上设置实际的路径 - 这将更加困难,因为Spring已经在自动装载服务的时候创建了SupportBean。您也许可以创建一个'SupportBeanFactory'或类似的自动装配。然后,工厂可以创建'SupportBean',将相关路径提供给'SupportBean'的构造函数。这将取决于你想要达到的目标。 –