如何在 Spring 应用程序上下文中将 Class<?> 设置为属性值?

Dim*_*ima 4 java spring inversion-of-control

有没有办法配置 spring 应用程序上下文,以便它使用 Class 类型的值初始化 setter?

我需要初始化该结构: Map<Class<?>, Object>

nic*_*ild 5

你有没有尝试过这样的事情:

<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>
Run Code Online (Sandbox Code Playgroud)