5

Consider I have something like this in beans.xml:

<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>

But I need to add emailList property into multiple beans. How can I do that without writing property to each bean? Can externalize property and inject it into each bean?

I expect something like:

<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>

1 Answer 1

3

You can do it using: util:list

   <util:list id="myList" value-type="java.lang.String"> 
      <value>foo</value> 
      <value>bar</value> 
   </util:list>

Then use this myList reference in other beans.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.