1、继承关系

bean-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-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;
}
@Override
public 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>

Spring4.0学习笔记(3) —— Spring_Bean之间的关系的更多相关文章

  1. Spring4.0学习笔记(11) —— Spring AspectJ 的五种通知

    Spring AspectJ 一.基于注解的方式配置通知 1.额外引入的jar包: a) com.springsource.org.aopalliance-1.0.0.jar b) com.sprin ...

  2. Spring4.0学习笔记(10) —— Spring AOP

    个人理解: Spring AOP 与Struts 的 Interceptor 拦截器 有着一样的实现原理,即通过动态代理的方式,将目标对象与执行对象结合起来,降低代码之间的耦合度,主要运用了Proxy ...

  3. Spring4.0学习笔记(7) —— 通过FactoryBean配置Bean

    1.实现Spring 提供的FactoryBean接口 package com.spring.facoryBean; import org.springframework.beans.factory. ...

  4. Spring4.0学习笔记(6) —— 通过工厂方法配置Bean

    1.静态工厂方法: bean package com.spring.factory; public class Car { public Car(String brand) { this.brand ...

  5. Spring4.0学习笔记(5) —— 管理bean的生命周期

    Spring IOC 容器可以管理Bean的生命周期,Spring允许在Bean生命周期的特定点执行定制的任务 Spring IOC 容器对Bean的生命周期进行管理的过程: 1.通过构造器或工厂方法 ...

  6. Spring4.0学习笔记(4) —— 使用外部属性文件

    1.配置xml文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...

  7. Spring4.0学习笔记(2) —— 自动装配

    Spring IOC 容器可以自动装配Bean,需要做的是在<bean>的autowire属性里指定自动装配的模式 1)byType 根据类型自动装配,若IOC 容器中有多个目标Bean类 ...

  8. Spring4.0学习笔记(1) —— 基础知识

    1.基本定义 IOC: 其思想是反转资源获取的方向,传统的资源查找方式要求组件向容器发起请求查找资源,作为回应,容器适时的返回资源,而应用了 IOC之后,容器主动将资源推送给它所管理的组件,组件索要做 ...

  9. Spring4.0学习笔记(12) —— JDBCTemplate 操作数据库

    整体配置 1.配置xml文件 <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi ...

随机推荐

  1. h.264 率失真优化

    Rate Distortion Optimization 搜索时,一个不可避免的问题就是如何对mv进行比较,从而得到最优 对于同一压缩算法来说,码率越高表示图像质量越好.失真越小,但是码率越高要求更大 ...

  2. 树形dp+MST-hdu-4126-Genghis Khan the Conqueror

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4126 题目意思: 给一图,n个点,m条边,每条边有个花费,给出q条可疑的边,每条边有新的花费,每条可 ...

  3. 最小费用最大流MCMF zkw费用流

    稀疏图慢死了...但是稠密图效果还是很好的 struct MCMF{ struct tedge{int x,y,cap,w,next;}adj[maxm];int ms,fch[maxn]; int ...

  4. HDOJ 1048 The Hardest Problem Ever(加密解密类)

    Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caes ...

  5. 查看Wii的系统版本信息

    Wii的系统版本信息在系统设置界面就能看到: Step1:主界面 > Wii Options Step2:选择右边的Wii Settings Step3:如下图所示,当前主机的系统版本是4.2U ...

  6. bzoj2208 [Jsoi2010]连通数(scc+bitset)

    2208: [Jsoi2010]连通数 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1879  Solved: 778[Submit][Status ...

  7. 男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略 - 国外 - 快鲤鱼

    男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略 - 国外 - 快鲤鱼 男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略

  8. 使用 FreeMarker 替换 JSP 的 10 个理由

    你还在使用 Java 服务器页面(俗称JSP)吗?我曾经也是,但是几年前我抛弃了它们,并且再也没有用过JSP了.JSP 是个很好的概念,但是它却剥夺了 web 开发的乐趣. 对我而言,这些都是小事,比 ...

  9. redis取值报错

    > get "all_couriers_on_the_job" (error) ERR Operation against a key holding the wrong k ...

  10. AIX Study之--AIX网卡配置管理(ent0、en0、et0)

    AIX Study之--AIX网卡配置管理(ent0.en0.et0) 1.查看AIX系统网卡信息: [root@aix211 /]#lsdev |grep et  en0 Available 1L- ...