Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring: a bean that receives a list of Classes

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.

like image 934
flybywire Avatar asked Oct 07 '09 14:10

flybywire


2 Answers

<property name="classes">
      <list>
          <bean class="java.lang.Class" factory-method="forName">
               <constructor-arg value="java.lang.String"/>
          </bean>
      </list>
</property>

Something like that...

like image 37
Droo Avatar answered Oct 13 '22 01:10

Droo


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

   <property name="classes">
      <list>
         <value>java.lang.String</value>
         <value>java.lang.Integer</value>
      </list>
   </property>
like image 172
skaffman Avatar answered Oct 13 '22 00:10

skaffman