spring: a bean that receives a list of Classes

拥有回忆 提交于 2019-12-12 10:44:29

问题


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.


回答1:


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

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



回答2:


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

Something like that...



来源:https://stackoverflow.com/questions/1532043/spring-a-bean-that-receives-a-list-of-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!