<?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/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd ">
  <bean id="English_level" class="com.myspring.second.EnglishLevel">
      <!-- set方法注入 -->
    <property name="course">
      <value>4级</value>
    </property>
  </bean>
  <bean id="Math_level" class="com.myspring.second.MathCourse">
    <!-- 构造函数注入 -->
    <constructor-arg><value>1001</value></constructor-arg>
    <constructor-arg><value>离散数学</value></constructor-arg>
  </bean>
  <bean id="student" class="com.myspring.second.Student">
    <property name="eng">
      <ref bean="English_level"/>
    </property>
    <property name="mat">
      <ref bean="Math_level"/>
    </property>
  </bean>

</beans>


例如上面这个文件:
  • 配置了3个bean
  • property 的 name 属性值,在实体 bean 中必须有对应的 set 方法,否则报错 ,报错如下:

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?


例如:
<bean id="student" class="com.myspring.second.Student">
    <property name="eng">
      <ref bean="English_level"/>
    </property>
    <property name="mat">
      <ref bean="Math_level"/>
    </property>
  </bean>
对于这个bean,在 Student 类中必须存在:
setEng(String string){}
setMat(String string){}
这两个方法;
set 方法写法就不详解了,略~

渣渣就得在 bug中挣扎

spring 的配置 bean>>property>>name属性的更多相关文章

  1. Spring配置Bean,为属性赋值

    SayHello的实体类: package com.langchao; /** * @ClassName: SayHello * @description: * @author: ZhangYawei ...

  2. spring FactoryBean配置Bean

    概要: 实例代码具体解释: 文件夹结构 Car.java package com.coslay.beans.factorybean; public class Car { private String ...

  3. 5.spring:注解配置 Bean

    在classpath中扫描组件 组键扫描:能够从classpath下自动扫描,侦测和实例化具有特定注解的组件 特定的组件包括: ->@Componment:基于注解,标识一个受Spring管理的 ...

  4. Spring 注解配置Bean

    一.使用注解配置Bean 1.注解 在类定义.方法定义.成员变量定义前使用.其简化<bean>标签,功能同<bean>标签.格式为: @注解标记名. 2.组件扫描 Spring ...

  5. 关于 spring MVC 配置自动扫描中 use-default-filters 属性

    1.springMVC 设置扫描 Bean 的两种常见写法 1.1.先看第一种常见的配置:默认 <!-- 配置Controller扫描 --> <context:component- ...

  6. 为什么Pojo类没有注解也没有spring中配置<bean>也能够被加载到容器中。

    Spring的注入机制其实就是代替了new的这个过程(称为解耦). 写了一个Thread类,没有加注解@Component,但是可以正常运行,开始为了自圆其说,打通逻辑,猜测是StartThread中 ...

  7. Spring基础——在Spring Config 文件中配置 Bean

    一.基于 XML 的 Bean 的配置——通过全类名(反射) <bean <!-- id: bean 的名称在IOC容器内必须是唯一的若没有指定,则自动的将全限定类名作为 改 bean 的 ...

  8. Spring配置bean的详细知识

    在Spring中配置bean的一些细节.具体信息请参考下面的代码及注释 applicationContext.xml文件 <?xml version="1.0" encodi ...

  9. Spring下如何配置bean

    本次讲述项目背景: 创建Service类,Service下用到dao类.通过在Spring中配置bean,实现在项目启动时,自动加载这个类 本次只讲述配置bean的注意事项,故只给出简单实例: 创建S ...

随机推荐

  1. 同样的一句SQL语句在pl/sql 代码块中count 没有数据,但是直接用SQl 执行却可以count 得到结果

    pl/sql 代码块: SELECT count(distinct t2.so_nbr) INTO v_count2 FROM KFGL_YW_STEP_qd t2 WHERE t2.partitio ...

  2. Linux中的文件上传下载

    1.部署ftp服务器 2.安装bypy python 客户端(还没试过,先记录一下) https://www.v2ex.com/t/124886

  3. Python中使用ElementTree解析xml

    在Python中,ElementTree是我们常用的一个解析XML的模块 1.导入ElementTree模块 from xml.etree import ElementTree as ET 2.初始化 ...

  4. C++学习笔记——一只P转C的OIer的学习历程

    2015-11-29 第一天接触c++(也不能这不说,看c++的程序也看了不少).重新找回了当时学pascal的感觉,从Hello World 开始写起,感觉自己的智商降低了,期间犯了各种弱智到不能再 ...

  5. 如何解决jenkins中shell脚本明明执行失败却不自行退出,且构建结果仍然显示success的问题??

    首先,需要明确shell命令执行结果$?为0或者非0仅能代表此执行语句是否顺利执行了,例如: 执行语句:adb connect 192.168.XX.XX 执行结果:unable to connect ...

  6. C#<热血传奇>服务端源代码再次给力更新

    前段时间一直在忙公司项目,最近抽点空稍微把部分代码重新整理一下(代码太久没碰很多地方都忘记了 囧~~~) 此次还是更新服务端,并修正上一版里面存在的很多指针 异常BUG...  (代码比较烂,还请各位 ...

  7. c++ 输入一行字符串

    ]; //cin>>str1; 方式1 不能统计(录入)空格后的字符 cin.); //方式2 能统计空格后输入的字符 按回车键输入结束 get()会将换行符保存在序列里 //gets(s ...

  8. 图文详解如何搭建Windows的Android C++开发环境

    原地址:http://www.apkbus.com/android-18595-1-1.html //================================================= ...

  9. easyui源码翻译1.32--Pagination(分页)

    前言 使用$.fn.pagination.defaults重写默认值对象下载该插件翻译源码 该分页控件允许用户导航页面的数据.它支持页面导航和页面长度选择的选项设置.用户可以在分页控件上添加自定义按钮 ...

  10. [topcoder]TallPeople

    水题.http://community.topcoder.com/stat?c=problem_statement&pm=2923&rd=5854 一开始错了是因为理解错题意.还有就是 ...