<?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. Source Insight 显示中文乱码

    Source Insight 3.X utf8支持插件震撼发布 继上次SI多标签插件之后,因为公司内部编码改为utf8编码,因此特意做了这个Source Insight 3.X utf8插件. 下载地 ...

  2. python 读写文本文件

    本人最近新学python ,用到文本文件的读取,经过一番研究,从网上查找资料,经过测试,总结了一下读取文本文件的方法. 1.在读取文本文件的时无非有两种方法: a.f=open('filename', ...

  3. java Arrays.asList()和Collections.addAll()

    java中的方法Arrays.asList(arg1,arg2,arg3...),经常用在将多个元素或数组转化为List中的元素,但是在使用的时候,应该注意: arg1决定返回list的元素类型(即第 ...

  4. 利用百度地图API,在浏览器中找到自己的位置

    首先你得有个百度地图的秘钥,http://lbsyun.baidu.com/apiconsole/key 剩下的就是编码了 这里面会用到一个javascript里的一个函数,getMyLocation ...

  5. ANGULAR 2 FOR REACT DEVELOPERS

    Now that Angular 2 is in beta, the time has come for us to drop everything and learn something new, ...

  6. http://blog.csdn.net/carolzhang8406/article/details/7196011

    http://blog.csdn.net/carolzhang8406/article/details/7196011

  7. Java缓存--JCS

    添加外部包: jcs-1.3.jar concurrent-10.3.jar cache.cff # optional region "myCache" specific conf ...

  8. SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-006-给bean运行时注入值(Environment,Property文件)

    一. 直观的给bean注入值如下: @Bean public CompactDisc sgtPeppers() { return new BlankDisc( "Sgt. Pepper's ...

  9. RecyclerView一个奇怪的npe异常

    java.lang.NullPointerException at android.support.v7.widget.RecyclerView.computeVerticalScrollOffset ...

  10. .Net remoting, Webservice,WCF,Socket区别

    传统上,我们把计算机后台程序(Daemon)提供的功能,称为"服务"(service).比如,让一个杀毒软件在后台运行,它会自动监控系统,那么这种自动监控就是一个"服务& ...