Spring4.0学习笔记(3) —— Spring_Bean之间的关系
1、继承关系
bean-relation.xml
<?xml version="1.0" encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><bean id="address" class="com.spring.relation.Address"><property name="city" value="beijing^"></property><property name="location" value="los angles"></property></bean><bean id="address2" parent="address"><property name="location" value="new York"></property></bean> </beans>
Address.java
package com.spring.autowire;public class Address {private String city;private String location;public String getCity() {return city;}public void setCity(String city) {this.city = city;}public String getLocation() {return location;}public void setLocation(String location) {this.location = location;}@Overridepublic String toString() {return "Address [city=" + city + ", location=" + location + "]";} }
测试
package com.spring.relation; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class main {public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("bean-relation.xml");Address address = (Address)ctx.getBean("address");System.out.println(address);Address address2 = (Address)ctx.getBean("address2");System.out.println(address2);} }
【拓展】 abstract = true的时候,该bean是无法被实例化的。可以去掉用于实例化的class 属性,这样该bean仅为模板bean
<bean id="address" class="com.spring.relation.Address" abstract="true"><property name="city" value="beijing^"></property><property name="location" value="los angles"></property></bean><bean id="address2" parent="address"><property name="location" value="new York"></property></bean>
转载于:https://www.cnblogs.com/cklovefan/p/5291289.html
Spring4.0学习笔记(3) —— Spring_Bean之间的关系相关推荐
- Spring4.0学习笔记(5) —— 管理bean的生命周期
Spring IOC 容器可以管理Bean的生命周期,Spring允许在Bean生命周期的特定点执行定制的任务 Spring IOC 容器对Bean的生命周期进行管理的过程: 1.通过构造器或工厂方法 ...
- mysql5.0镜像_Mysql5.0学习笔记(一)
Mysql5.0学习笔记(一) -基本sql语句与支持字符集 1.登录 mysql -h localhost -u root 2.创建用户firstdb(密码firstdb)和数据库,并赋予权限于fi ...
- flink1.12.0学习笔记第2篇-流批一体API
flink1.12.0学习笔记第 2 篇-流批一体API flink1.12.0学习笔记第1篇-部署与入门 flink1.12.0学习笔记第2篇-流批一体API flink1.12.0学习笔记第3篇- ...
- CCC3.0学习笔记_认证和隐私保护
CCC3.0学习笔记_Authentication and Privacy Keys 系列文章目录 文章目录 系列文章目录 前言 1. 手机端和车厂服务器端的密钥存储 2. 密钥的产生和使用的说明 3 ...
- TensorFlow2.0 学习笔记(三):卷积神经网络(CNN)
欢迎关注WX公众号:[程序员管小亮] 专栏--TensorFlow学习笔记 文章目录 欢迎关注WX公众号:[程序员管小亮] 专栏--TensorFlow学习笔记 一.神经网络的基本单位:神经元 二.卷 ...
- Tensorflow2.0学习笔记(二)
Tensorflow2.0学习笔记(二)--Keras练习 文章目录 Tensorflow2.0学习笔记(二)--Keras练习 前言 二.使用步骤 1.实现步骤及代码 2.下载 Fashion MN ...
- Tensorflow2.0学习笔记(一)北大曹健老师教学视频1-4讲
Tensorflow2.0学习笔记(一)北大曹健老师教学视频1-4讲 返回目录 这个笔记现在是主要根据北京大学曹健老师的视频写的,这个视频超级棒,非常推荐. 第一讲 常用函数的使用(包含了很多琐碎的函 ...
- CCC3.0学习笔记_证书数据
CCC3.0学习笔记_证书数据 系列文章目录 文章目录 系列文章目录 前言 1. [A] - SE Root CA Certificate 2. [B] - SE Root Certificate 3 ...
- 【面向对象】 JML(Level 0) 学习笔记
JML Level 0 学习笔记 注释结构 JML表达式 原子表达式 量化表达式 集合表达式 操作符 方法规格 类型规格 约束限制 方法与类型规格的关系 一个完整例子 JML是用于对Java程 在 ...
最新文章
- Git + BeyondCompare
- windows下硬盘安装mint10
- C# 与 Unity 同名函数
- boost::mp11::mp_replace_second相关用法的测试程序
- [Leetcode总结] 102.二叉树的层序遍历
- qt如何做到实时显示数据_Python 如何实时绘制数据
- 【CodeForces - 616D 】Longest k-Good Segment (twopointer,尺取)
- .NET_.NET Copy Web 部署概念_01-3
- 炸了!亚马逊薪资文件泄露!原来这么多人年薪百万
- map-reduce 、map、reduce
- 【汇编优化】之X86汇编优化
- java ipv4和ipv6通信_IPv6与IPv4连接负载
- 并发编程模型Akka
- [转]Cocos2d-x下Lua调用自定义C++类和函数的最佳实践
- Activity获得焦点----onWindowFocusChanged
- 将win7 firefox WebStorm PyCharm等JetBrains系列开发软件设置为豆沙绿护眼背景
- Ubuntu18.04系统硬盘分区方法
- ArrayList删除元素的细则
- 怎么运行c语言程序,如何使用C语言进行编程操作,教程在这里,C语言编程快速入门...
- [BJDCTF 2nd]fake google -wp
热门文章
- windows等宽字体
- [转]给控件做数字签名
- java jni ubuntu 环境搭建时遇到的坑
- 前端学习(3288):object.define
- 前端学习(3166):react-hello-react之鼠标移入效果
- [css] css3的:nth-child和:nth-of-type的区别是什么?
- 前端学习(2755):配置tabber其他属性
- 前端学习(2669): vue3.0实战开始建立新项目
- 工作64:element多选功能
- 前端学习(1732):前端系列javascript之状态切换