How to set Class<?> as property value in spring application context?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 18:18:31

问题


Is there a way to configure spring application context so it will initialize the setter with value of type Class?

I need to initialize that structure: Map<Class<?>, Object>


回答1:


Have you tried something like this:

<bean id="myBean" class="myBean">
  <!-- This will set a map onto the property classMap of myBean -->
  <property name="classMap">
    <map key-type="java.lang.Class">
      <entry key="java.lang.String" value="A String keyed by the class 'java.lang.String'" />
    </map>
  </property>
</bean>


来源:https://stackoverflow.com/questions/7095637/how-to-set-class-as-property-value-in-spring-application-context

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