Spring配置文件applicationContext.xml中bean>>property>>name属性表示的含义

首先我们知道property是bean元素的子元素,它用于调用Bean实例中的setter方法用于完成属性赋值,从而实现依赖注入。其name属性表示Bean实例中的相应属性,ref属性用于指定其属性值(就是你要连接的bean的id)

例子:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
<bean id="userDao" class="com.itheima.userDaoImpl">
<bean id="customerDao" class="com.itheima.customerDaoImpl">
<bean id="service" class="com.itheima.serviceDaoImpl">
<property name="age" ref="userDao">
<property name="phone" ref="customerDao">
</beans>

例如:

<bean id="service" class="com.itheima.serviceDaoImpl">
<property name="age" ref="userDao">
<property name="phone" ref="customerDao">

对于这个bean,在 Service类中必须存在:
setAge(String string){}
setPhone(String string){}
这两个方法;
如果没有这两个setter方法或者name属性的值不是(Age/age)(Phone/phone)就会报错:
Bean property ‘某某属性’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Spring配置文件applicationContext.xml中bean>>property>>name属性的含义相关推荐

  1. Spring 配置文件applicationContext.xml

    Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸". Spring配置文件是一个或多个标准的XML文档,applica ...

  2. Spring配置文件applicationContext.xml的两种拆分方式

    第一种: 通过web.xml配置加载spring上下文环境,其配置方式如下: web.xml [xhtml] view plain copy <context-param> <par ...

  3. spring配置文件ApplicationContext.xml里面class等没有提示功能

    实现效果: 解决方法: windows–>preference->myeclipse->files and editors–>xml->xmlcatalog 点击add ...

  4. ssm(Spring+Spring mvc+mybatis)Spring配置文件——applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  5. spring 的 applicationcontext.xml

    以下是详解Spring的applicationContext.xml文件代码: <!-- 头文件,主要注意一下编码 --> <?xml version="1.0" ...

  6. Spring中bean标签的属性和值:

    Spring中bean标签的属性和值: <bean name="user" class="com.pojo.User" init-method=" ...

  7. 在配置文件web.xml中配置Struts2的启动信息

    在配置文件web.xml中配置Struts2的启动信息: <?xml version="1.0" encoding="UTF-8"?> <we ...

  8. spring使用中applicationContext.xml文件头部声明

    spring使用中applicationContext.xml文件头部声明 <beans xmlns="http://www.springframework.org/schema/be ...

  9. Spring之使用注解实例化Bean并注入属性

    1.准备工作 (1)导入jar包 除了上篇文章使用到的基本jar包外,还得加入aop的jar包,所有jar包如下 所需jar包 (2)配置xml <?xml version="1.0& ...

最新文章

  1. 安装pr_PR 一键转场插件 安装教程
  2. T1330 最少步数(#Ⅱ- 8)(广度优先搜索)
  3. SAP产品概念及版本简介
  4. vs2015 单元测试 linux,VS2015做单元测试
  5. 设置断点检测控件何时创建和析构
  6. 云数据库·ApsaraDB 产品6月刊
  7. NAND FLASH Controler for IMX31
  8. Kaggle新赛:通过音频识别鸟类和青蛙物种
  9. softmax ce loss_从Softmax到AMSoftmax(附可视化代码和实现代码)
  10. 让Windows Server 2008+IIS 7+ASP.NET支持10万个同时请求
  11. effective C++ 条款 48:认识template元编程
  12. PS打造电影金属字体
  13. Linux编程基础 5.2:消息队列
  14. Hexo添加小部件(Butterfly主题) 添加卡通人物(看板娘)
  15. python电影推荐系统_电影推荐系统---协同过滤算法(SVD,NMF)
  16. 基于stm32的智能婴儿床(毕业设计)
  17. assist 下载链接
  18. 【Kafka】Kafka为什么快?
  19. Moffitt研究人员确定了为什么CAR T治疗可能对某些淋巴瘤患者无效
  20. 来黑马,赢得漂亮!(黑马11月开班时间)

热门文章

  1. 《领域驱动设计》阅读笔记 第1章 消化知识
  2. 关于卸载系统级应用的那点事
  3. golang之iota常量与枚举标识
  4. 智慧屏鸿蒙os系统,在鸿蒙OS 2.0来临之际,华为智慧屏够智慧吗?
  5. 高光谱遥感图像的分类
  6. 以下系统不属于计算机软件,微型计算机的微处理器芯片上集成了(以下不属于计算机软件系统的是...
  7. win10 135/445端口关闭
  8. c++ Qt 设置widget背景
  9. Android 读取excel (支持 xls和xlsx)
  10. mSystems:苏晓泉、徐健-基于大数据引擎的全球微生物组转化网络