开发者

spring: a bean that receives a list of Classes

开发者 https://www.devze.com 2022-12-08 02:32 出处:网络
I want to define in my Spring XML conte开发者_C百科xt a bean that has a property of the type List of classes: i.e. List<Class<?>> classes

I want to define in my Spring XML conte开发者_C百科xt 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.


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

   <property name="classes">
      <list>
         <value>java.lang.String</value>
         <value>java.lang.Integer</value>
      </list>
   </property>


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

Something like that...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号