Configure a bean with map property

1、Using XML

  <bean id="sqlService" class="SqlService">
    <property name="dataSourceMap">
      <map>
        <entry key="a">
          <ref bean="dataSourceA"/>
        </entry>
        <entry key="b">
          <ref bean="dataSourceB"/>
        </entry>
      </map>
    </property>
  </bean>

 2、Using the Spring DSL

beans = {
   def dsMap = new HashMap()
   dsMap.put('a',  ref('dataSourceA') )
   dsMap.put('b',  ref('dataSourceB') )

   sqlService(SqlService) {
       dataSourceMap = dsMap
  }
  ...
}
 

你可能感兴趣的:(spring,bean,xml)