Spring_Bean 之间的关系

beans-relation.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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.xsd">
<!--
<bean id="address" class="com.hy.spring.beans.autowire.Address"
p:city="BeiJing^" p:street="HuiLongGun">
</bean>
-->
<!--
抽象bean: bean的 abstract属性为true的bean. 这样的bean不能被IOC 容器实例化,只能被继承配置
若某一个bean的class 属性没有指定,则该bean必须是一个抽象的bean
-->
<bean id="address" p:city="BeiJing^" p:street="HuiLongGun" abstract="true">
</bean>
<bean id="address1" class="com.hy.spring.beans.autowire.Address"
p:city="BeiJing" p:street="WuDaoKou" parent="address">
</bean>
</beans>
Main.java
package com.hy.spring.beans.relation;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.hy.spring.beans.autowire.Address;
public class Main {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans-relation.xml");
//Address address = (Address) ctx.getBean("address");
//System.out.println(address);
Address address = (Address) ctx.getBean("address1");
System.out.println(address);
}
}

XML 配置
<bean id="car" class="com.hy.spring.beans.autowire.Car"
p:brand="Audi" p:price="300000">
</bean>
<!--
要求再配置person时,必须有一个关联的car!
换句话说person 这个bean 依赖于Car 这个bean
-->
<bean id="person" class="com.hy.spring.beans.autowire.Person"
p:name="Tom" p:address-ref="address1" depends-on="car">
</bean>
Spring_Bean 之间的关系的更多相关文章
- Spring4.0学习笔记(3) —— Spring_Bean之间的关系
1.继承关系 bean-relation.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...
- .NET Core与.NET Framework、Mono之间的关系
随着微软的.NET开源的推进,现在在.NET的实现上有了三个.NET Framework,Mono和.NET Core.经常被问起Mono的稳定性怎么样,后续Mono的前景如何,要回答这个问题就需要搞 ...
- .NET Core 和 .NET Framework 之间的关系
引用一段描述:Understanding the relationship between .NET Core and the .NET Framework. .NET Core and the .N ...
- 实体之间的关系【Entity Relationships】(EF基础系列篇9)
Here, you will learn how entity framework manages the relationships between entities. Entity framewo ...
- php CGI、Fastcgi、PHP-FPM的详细介绍与之间的关系
以下PHP CGI.Fastcgi.PHP-FPM的一些信息归纳和汇总----->详细介绍与之间的关系 一:CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的 web ...
- [转] valuestack,stackContext,ActionContext.之间的关系
三者之间的关系如下图所示: ActionContext 一次Action调用都会创建一个ActionContext 调用:ActionContext context = ActionContext ...
- angular源码阅读,依赖注入的原理:injector,provider,module之间的关系。
最开始使用angular的时候,总是觉得它的依赖注入方式非常神奇. 如果你跳槽的时候对新公司说,我曾经使用过angular,那他们肯定会问你angular的依赖注入原理是什么? 这篇博客其实是angu ...
- JavaScript和Java之间的关系
今天来简单而又详细地说说JavaScript和Java的关系. 开门见山总结性一句话,它们之间的关系 = 雷锋和雷峰塔之间的关系,换句话说:它们之间没什么关系. 但往往有不少初学者甚至中级者认为它们之 ...
- PHP类和对象之间的关系
类是对象的描述: 类和对象之间的关系类似于建房子的图纸和房子: 创建类--new对象--用对象: 一.对象的两个特性: --对象的行为(功能):可以对对象施加操作,例如,电视机的开.关.转换频道: - ...
随机推荐
- SurvivalShooter学习笔记(七.玩家射击)
玩家射击:(这个脚本放在玩家的空子物体上,这个位置为枪口位置) 点击鼠标,玩家射击: 射击枪口发光,射击通过射线,方向有激光效果:(关于射线不明白可以参考Unity射线相关) 射击有射击音效 射击有每 ...
- 基础知识《十三》深入浅出Java回调机制
本文转载自http://hellosure.iteye.com/blog/1130176 在网上看到了一个比喻,觉得很形象,这里借用一下: 你有一个复杂的问题解决不了,打电话给你的同学,你的同学说可以 ...
- 网络虚拟化之FlowVisor:网络虚拟层(上)
概念解释:切片:虚拟网络的一个实例 一. 网络虚拟化(虚拟网络) 人类社会的发展在很大方面得益于自然界,飞机受益于鸟,雷达受益于蝙蝠等等,所以专门有个学科为仿生学就是研究和模仿生物的特殊本质,利用生物 ...
- Less-Mixins分离规则集
//Mixins --立即执行函数 .test{/* */} #test{/* */} --指定执行函数 .test(){/* */} #test(){/* */} --调用: .test; or . ...
- Flutter入门之有状态组件
StatefulComponent使用方法入门 在上一篇Flutter入门之无状态组件中我们讲到了无状态组件,所谓的无状态组件指的就是其内部的状态是来自其父组件并使用final类型的变量来存储,当组件 ...
- The 12 Months of the Year
- pro-select-like
DELIMITER | drop procedure if exists pro_query; CREATE PROCEDURE pro_query ( cname VARCHAR() ) BEGIN ...
- Linux基础服务
作业一:nginx服务1.二进制安装nginx包 [root@bogon ~]# systemctl disable firewalld #关闭Firewalld自启动 Removed symlink ...
- centos7 docker镜像加速器配置
CentOS的配置方式略微复杂,需要先将默认的配置文件复制出来 /lib/systemd/system/docker.service -> /etc/systemd/system/docker. ...
- List、Map、Set三个接口,存取元素时,各有什么特点?
List与Set都是单列元素的集合,它们有一个功共同的父接口Collection. Set里面不允许有重复的元素, 存元素:add方法有一个boolean的返回值,当集合中没有某个元素,此时add方法 ...