5
考慮我在beans.xml中是這樣的:春天。如何將相同的屬性添加到多個bean?
<bean id="emails" class="org.some.package.SomeClass">
<property name="emailList">
<list>
<value>[email protected]</value>
<value>[email protected]</value>
<value>[email protected]</value>
<value>[email protected]</value>
</list>
</property>
</bean>
但我需要的emailList屬性添加到多個豆。我怎麼能做到這一點,而不寫入每個bean的屬性?可以將屬性外部化並將其注入到每個bean中?
我希望是這樣的:
<property name="commonProp">
<list>
<value>[email protected]</value>
<value>[email protected]</value>
<value>[email protected]</value>
<value>[email protected]</value>
</list>
</property>
<bean id="emailsOne" class="org.some.package.ClassOne">
<property name="emailList" ref="commonProp" />
</bean>
<bean id="emailsTwo" class="org.some.package.ClassTwo">
<property name="emailList" ref="commonProp" />
</bean>