spring的Bean注入和P標籤使用
1.構造方法引數 對應 配置檔案 <constructor-arg> 元素
可以index|name|type 三選一 、三選二 ; ref|value 二選一
2. setter方法注入(開發推薦)
為需要注入屬性提供setter方法
配置 每個注入屬性, 對應<property> 元素
3. p名稱空間的使用
spring2.5以後,為了簡化setter方法屬性注入,引用p名稱空間的概念,可以將<property> 子元素,簡化為<bean>元素屬性配置 !!
a.
在applicationContext.xml 引入p 名稱空間
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
b. 簡化注入的配置
4. 集合型別的屬性注入(瞭解)
Spring 對每個常用集合物件,提供單獨元素完成注入
List 物件 ---- <list> 元素
Set 物件 ---- <set> 元素
Map物件 ----<map>元素
Properties 物件 ---- <props> 元素
集合屬性的注入,主要用於框架的配置 !