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> 元素

集合屬性的注入,主要用於框架的配置 !


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM