Create spring beans, based on a comma-separated list of classes

Posted by Jeroen on Stack Overflow See other posts from Stack Overflow or by Jeroen
Published on 2010-05-18T06:42:39Z Indexed on 2010/05/18 7:10 UTC
Read the original article Hit count: 320

Filed under:
|
|

Is there a way in Spring to create a collection, or array, of beans, based on a comma-separated list of classes. For example:

package mypackage;
public class Bla {
 private Set<MyBean> beans;
 public void setBeans(Set<MyBean> beans) {
  this.beans = beans;
 }
}

With the application context:

<bean id="bla" class="mypackage.Bla">
 <property name="beans">
  <set>
   <bean class="mypackage.Bean1, mypackage.Bean2" />
  </set>
 </property>
</bean>

Preferably the beans are all initialized and wired from the context, leaving the code as simplistic as possible, is this possible?

© Stack Overflow or respective owner

Related posts about spring

Related posts about beans