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