zoukankan      html  css  js  c++  java
  • spring 的配置 bean>>property>>name属性

    <?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中挣扎



  • 相关阅读:
    软件工程(2018)结对编程第二次作业
    软件工程(2019)结对编程第一次作业
    软件工程(2019)第三次个人作业
    软件工程(2019)第二次作业
    软件工程(2019)第一次作业
    实用的小工具
    php中需要注意的函数(持续更新)
    sql 防注入(更新问题)
    laravel 中将一对多关联查询的结果去重处理
    调试location指令时,直接让location输出文本
  • 原文地址:https://www.cnblogs.com/zhanyao/p/4409231.html
Copyright © 2011-2022 走看看