---
title: "Configure a bean with map property "
author: "boogie"
date: "2008-05-26T10:33:07Z"
tags: []
slug: "configure-a-bean-with-map-property"
draft: false
lastmod: "2008-05-26T10:33:07Z"
id: 196904
url: "https://boogie.iteye.com/blog/196904"
---

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
  }
  ...
}
```