spring对象【bean】之间的属性是通过什么维护的:

    1、构造方法:标签:constructor-arg

    2、set方法:标签:property

  1. <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-4.0.xsd">
  2.  
  3. <!--
    标签"高亮"取决与上面的配置,该内容可作为模版使用
    -->
  4.  
  5. <bean id="user" class="Cristin.Spring.User">
    <!--<property name="name" value="杨晓龙"></property> -->
    <!--<property name="age" value="18"></property>-->
    <!--
    注意:
    1、value单独拉出来写的时候,注意类型,不需要引号
    2、name对应方法里的属性
    -->
    <!--<property name="age">
    <value>18</value>
    </property>
    <property name="car" ref="carId"></property>
    -->
    <!--
    构造器,如果User类存在带参数的新的构造方法,那么就需要构造器来对构造方法进行赋值,类的执行中,是先编译构造方法后再执行get、set,
    因此,该场景配置下 包蕾 19 数据会被后来的杨晓龙 18 所覆盖
    -->
  6.  
  7. <constructor-arg index="0"><value>包蕾</value></constructor-arg>
    <constructor-arg index="1"><value>19</value></constructor-arg>
  8.  
  9. <!--<constructor-arg index="2" ref="carId"></constructor-arg>-->
  10.  
  11. <constructor-arg index="2">
    <ref bean="carId"></ref>
    </constructor-arg>
    <property name="carList">
    <list>
    <!--简单的写法:直接通过ref引用外面的,ref表示引用哪个对象-->
    <ref bean="carId"></ref>
    <ref bean="carId"></ref>
    <!--复杂的写法:自己直接插数据-->
    <bean id="newcar" class="Cristin.Spring.Car">
    <property name="brand" value="奔驰"></property>
    <property name="price" value="500000"></property>
    </bean>
    </list>
    </property>
  12.  
  13. <property name="carSet">
    <set>
    <!--简单的写法:直接通过ref引用外面的,ref表示引用哪个对象-->
    <ref bean="carId"></ref>
    <ref bean="carId"></ref>
    <!--复杂的写法:自己直接插数据-->
    <bean id="newcar" class="Cristin.Spring.Car">
    <property name="brand" value="奔驰"></property>
    <property name="price" value="500000"></property>
    </bean>
    </set>
    </property>
  14.  
  15. <property name="carMap">
    <map>
    <entry key="name" value="杨子昫"></entry>
    <entry key="age" value="18"></entry>
    <entry key="car">
    <bean class="Cristin.Spring.Car">
    <property name="price" value="130000"></property>
    <property name="brand" value="雪弗兰"></property>
    </bean>
    </entry>
    <entry key="car2" value-ref="carId"></entry>
    </map>
    </property>
    </bean>
  16.  
  17. <bean id="carId" class="Cristin.Spring.Car">
    <property name="brand" value="大众"></property>
    <property name="price" value="1800000"></property>
    </bean>
  18.  
  19. </beans>

bean之间的属性是怎么维护的的更多相关文章

  1. [原创]java WEB学习笔记99:Spring学习---Spring Bean配置:自动装配,配置bean之间的关系(继承/依赖),bean的作用域(singleton,prototype,web环境作用域),使用外部属性文件

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  2. 3.spring:自动装配/Bean之间的关系/作用域/外部文件/spel/

    1.自动装配/手动装配 xml配置文件里的bean自动装配 Spring IOC 容器里可以自动的装配Bean,需要做的仅仅是在<bean>的autowire属性里面指定自动装配模式 -& ...

  3. Spring框架是怎么解决Bean之间的循环依赖的 (转)

    问题: 循环依赖其实就是循环引用,也就是两个或则两个以上的bean互相持有对方,最终形成闭环.比如A依赖于B,B依赖于C,C又依赖于A.如下图:   如何理解“依赖”呢,在Spring中有: 构造器循 ...

  4. Spring基础——在 IOC 容器中 Bean 之间的关系

    一.在 Spring IOC 容器中 Bean 之间存在继承和依赖关系. 需要注意的是,这个继承和依赖指的是 bean 的配置之间的关系,而不是指实际意义上类与类之间的继承与依赖,它们不是一个概念. ...

  5. Spring Bean之间的关系

    bean之间的关系:继承和依赖继承bean的配置 Spring允许继承bean的配置,被继承的bean称为父bean,继承这个父bean的bean称为子bean 子bean从父bean中继承配置,包括 ...

  6. Bean之间的关系

    Bean之间主要有继承和依赖的关系,这里的继承并不是我们面向对象里面所提到的继承. 继承 我们先来创建一个新的配置文件beans-relation.xml <bean id="addr ...

  7. spring bean之间的关系:继承,依赖,注入

    一 继承 spring中多个bean之间的继承关系,和面向对象中的继承关系类似,直接看代码. 先定义一个Person类 package com.demo.spring.entity; /** * @a ...

  8. bean之间的继承和依赖关系

    继承Bean配置 Spring允许继承bean的配置,被继承的bean称为父bean,继承这个父Bean的Bean称为子Bean 子Bean从父Bean中继承配置,包括Bean的属性配置 子Bean可 ...

  9. Spring(九):Spring配置Bean(二)自动装配的模式、Bean之间的关系

    XML配置里的Bean自动装配 Spring IOC容器可以自动装配Bean,需要做的仅仅是在<bean>的autowire属性里指定自动装配的模式,模式包含:byType,byName, ...

随机推荐

  1. golang学习笔记11 golang要用jetbrain的golang这个IDE工具开发才好

    golang学习笔记11   golang要用jetbrain的golang这个IDE工具开发才好  jetbrain家的全套ide都很好用,一定要dark背景风格才装B   从File-->s ...

  2. 75.Java异常处理机制-手动抛出异常

    package testDate; import java.io.File; import java.io.FileNotFoundException; public class TestReadFi ...

  3. checkbox 全选效果

    html部分 <p id="all">全选</p> <input type="checkbox" /><br/> ...

  4. c#md5加密的简单用法

    using System.Security.Cryptography; //MD5 md5 = MD5.Create(); MD5 md5 = new MD5CryptoServiceProvider ...

  5. 安装使用zookeeper

    1,加压 2,复制zoo_sample.cfg命名为zoo.cfg 3,在conf同级目录下新建一文件夹 data 4,修改数据存放目录 5,启动zookeeper

  6. QMenu 设置菜单图标 & 生成菜单树

    效果图 源码 .h 文件 protected slots: void onMenuTriggered(QAction*); .cpp 文件 // 菜单 QMenu *pMenu = new QMenu ...

  7. js动态添加和删除table的行例子

    <table id="table_report" class="table table-striped table-bordered table-hover&quo ...

  8. scrapy instantiation

    start from scrapy.cmdline import execute execute(['scrapy', 'crawl', 'jokespider']) items.py import ...

  9. 单元测试Mock框架Powermockito 【mockito1.X】

    <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> &l ...

  10. P1382 楼房

    P1382 楼房 每个矩形拆成2个坐标按$x$轴排序,蓝后$multiset$维护最高值. #include<iostream> #include<cstring> #incl ...