spring 依赖注入bean的属性
来源:互联网 发布:淘宝网小衫春季女 编辑:程序博客网 时间:2024/05/20 17:28
对于类成员变量,spring支持构造函数注入,属性setter方法注入
0. domain类
public class Student {private String name;private int age;public Student(){}public Student(String name,int age){this.name=name;this.age =age ;}public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic String toString() {return "Student [name=" + name + ", age=" + age + "]";}
1.使用构造方法注入 通过 constructor 标签注入
<bean id="student" class="com.zmf.domain.Student"><!-- index 属性 --><!-- <constructor-arg index="0" value="zmf"></constructor-arg><constructor-arg index="1" value="11"></constructor-arg> --><!-- type 属性 --><constructor-arg type="int" value="111"></constructor-arg><constructor-arg type="java.lang.String" value="xxxs"></constructor-arg></bean>
<bean id="student" class="com.zmf.domain.Student"><property name="name" value="zmf"></property><property name="age" value="111"></property></bean>
-- 注入其他属性
public class Classroom {private Student student;public void setStudent(Student student){this.student = student;}
<bean id="classroom" class="com.zmf.domain.Classroom"><property name="student" ref="student"></property></bean>
List属性注入
<property name="list"> <list> <value>aaa</value> <value>bbb</value> </list></property>map属性注入
<property name=""><map><entry key="" value=""></entry><entry key="" value=""></entry></map></property>
set属性注入
<property name=""><set><value></value><value></value></set></property>
properties 注入
private Properties pro;
<property name="pro"><props><prop key="name">zmf</prop><prop key="age">11</prop></props></property>
阅读全文
0 0
- spring 依赖注入bean的属性
- Spring中bean的依赖注入解析
- spring源码解读 Bean的依赖注入
- Spring属性注入Bean的List属性
- [Spring] 注入Bean属性
- spring属性依赖注入
- Spring的depends-on属性Bean依赖
- Spring的depends-on属性Bean依赖
- Spring 之 Bean的属性注入
- Spring中Bean的简单属性注入
- Spring中Bean的复杂属性注入
- 【spring-bean】浅谈Spring的依赖注入(基础)
- 1.Spring bean常见属性的注入:bean
- Spring 有生命周期的bean的依赖注入
- Spring 有生命周期的bean的依赖注入
- Spring的配置、生命周期、依赖注入bean的操作
- spring的管理bean和依赖注入的原理剖析
- spring 配置bean的方法及依赖注入发方式
- 逛Github网站显示中文教程
- 目标检测之R-CNN 汇报
- C++17中那些值得关注的特性
- 让a标签href链接失效
- 移动硬盘上安装WIN7 WIN10系统
- spring 依赖注入bean的属性
- 使用 PowerShell 创建 Linux 虚拟机
- 视频编解码学习之二:编解码框架
- 顏色和編碼?兩者有關係嗎?
- Unity安卓交互
- 安装barbican服务
- VMWare使用rhel7.2(一)
- CDH Oozie 安装,使用,优化小技巧
- Jetson TX1/TX2配置教程--拷贝离线安装包