---
title: "尚学堂_Spring_0700_IOC_Collections"
author: "listen-raining"
date: "2014-10-11T23:18:50Z"
tags: []
categories: ["开源软件"]
slug: "spring-0700-ioc-collections"
draft: false
lastmod: "2014-10-11T23:18:50Z"
id: 2128696
url: "https://listen-raining.iteye.com/blog/2128696"
---

Spring集合注入的配置方式如下：

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
       xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
       xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)  
           [http://www.springframework.org/schema/beans/spring-beans-2.5.xsd](http://www.springframework.org/schema/beans/spring-beans-2.5.xsd)"&gt;

  &lt;bean id="u" class="com.bjsxt.dao.impl.UserDAOImpl"&gt;  
  &lt;/bean&gt;  
   
  &lt;bean id="userService" class="com.bjsxt.service.UserService"&gt;  
    &lt;!-- Setter Injection --&gt;  
   
    &lt;property name="userDAO" ref="u" /&gt;  
   
     
   &lt;!-- Constructor Injection --&gt;  
   &lt;!--&lt;constructor-arg ref="u"&gt;  &lt;/constructor-arg&gt;

  --&gt;  
  &lt;/bean&gt;  
   
  &lt;bean name="userDao" class="com.bjsxt.dao.impl.UserDAOImpl"&gt;  
    &lt;property name="sets"&gt;  
     &lt;set&gt;  
      &lt;value&gt;1&lt;/value&gt;  
      &lt;value&gt;2&lt;/value&gt;  
     &lt;/set&gt;  
    &lt;/property&gt;  
     
    &lt;property name="lists"&gt;  
     &lt;list&gt;  
      &lt;value&gt;1&lt;/value&gt;  
      &lt;value&gt;2&lt;/value&gt;  
      &lt;value&gt;3&lt;/value&gt;  
     &lt;/list&gt;  
    &lt;/property&gt;  
     
    &lt;property name="maps"&gt;  
       &lt;map&gt;  
          &lt;entry&gt;  
              &lt;key&gt;&lt;value&gt;1&lt;/value&gt; &lt;/key&gt;  
              &lt;value&gt;1&lt;/value&gt;  
          &lt;/entry&gt;  
          &lt;entry&gt;  
              &lt;key&gt;&lt;value&gt;2&lt;/value&gt;&lt;/key&gt;  
              &lt;value&gt;2&lt;/value&gt;  
          &lt;/entry&gt;  
          &lt;entry&gt;  
              &lt;key&gt;&lt;value&gt;3&lt;/value&gt;&lt;/key&gt;  
              &lt;value&gt;3&lt;/value&gt;  
          &lt;/entry&gt;  
       &lt;/map&gt;  
    &lt;/property&gt;  
  &lt;/bean&gt;

&lt;/beans&gt;

 

 

参考：spring-framework-2.5.6-with-dependencies\\spring-framework-2.5.6\\docs\\reference\\html\_single\\index.html 中的3.3.2.4章节。