---
title: "尚学堂_Spring_0300_IOC_Injection_Type"
author: "listen-raining"
date: "2014-10-11T23:06:59Z"
tags: []
categories: ["开源软件"]
slug: "spring-0300-ioc-injection-type"
draft: false
lastmod: "2014-10-11T23:06:59Z"
id: 2128691
url: "https://listen-raining.iteye.com/blog/2128691"
---

Spring的三种注入类型：  
 1. Setter Injection (Setter注入)  
 2. Constructor Injection (构造注入)  
 3    接口注入  
   
参考：spring-framework-2.5.6-with-dependencies\\spring-framework-2.5.6\\docs\\reference\\html\_single\\index.html 中的3.3.1章节。

 

 

具体配置参考如下：

&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;!--  
    &lt;property name="userDAO" ref="u" /&gt;  
    --&gt;  
     
   &lt;!-- Constructor Injection --&gt;  
   &lt;constructor-arg ref="u"&gt;  &lt;/constructor-arg&gt;  
     
     
     
  &lt;/bean&gt;  
 

&lt;/beans&gt;