views:

214

answers:

2

I want to define in my Spring XML context a bean that has a property of the type List of classes: i.e. List<Class<?>> classes

How do I send that bean a number of classes, say java.lang.String and java.lang.Integer?

The list needs not be reusable, i.e. I will not refer to it in another bean.

+9  A: 

With Spring, the simplest possibility usually works.....

   <property name="classes">
      <list>
         <value>java.lang.String</value>
         <value>java.lang.Integer</value>
      </list>
   </property>
skaffman
Why this works: http://static.springsource.org/spring/docs/2.5.x/reference/validation.html#beans-beans-conversion
matt b
skaffman is correct. To give you the gist of matt b's link, the Springframework uses property editors and introspection to determine what type of property you're setting and convert the given values accordingly.
Alex Marshall
A: 
<property name="classes">
      <list>
          <bean class="java.lang.Class" factory-method="forName">
               <constructor-arg value="java.lang.String"/>
          </bean>
      </list>
</property>

Something like that...

Droo