博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring中bean配置的继承
阅读量:7046 次
发布时间:2019-06-28

本文共 1509 字,大约阅读时间需要 5 分钟。

In Spring, the inheritance is supported in bean configuration for a bean to share common values, properties or configurations.

A child bean or inherited bean can inherit its parent bean configurations, properties and some attributes. In additional, the child beans are allow to override the inherited value.

例子如下:

public class Customer { 	private int type;	private String action;	private String Country; 	//... }

  

  

public class App {    public static void main( String[] args )    {    	ApplicationContext context = 			new ClassPathXmlApplicationContext("SpringBeans.xml");     	Customer cust = (Customer)context.getBean("CustomerBean");    	System.out.println(cust);     }}

  运行结果为:Customer [type=1, action=buy, Country=Malaysia]

In above example, the ‘BaseCustomerMalaysia’ is still able to instantiate, for example,

 

Customer cust = (Customer)context.getBean("BaseCustomerMalaysia");

  类似于java的抽象类,我们可以有:(注意abstract="true")

  现在当你运行:

Customer cust = (Customer)context.getBean("BaseCustomerMalaysia");

  将会出现:

org.springframework.beans.factory.BeanIsAbstractException: 	Error creating bean with name 'BaseCustomerMalaysia': 	Bean definition is abstract

Pure Inheritance Template

  也可以重写值:

  

 

转载地址:http://quzol.baihongyu.com/

你可能感兴趣的文章
rsync入门使用
查看>>
bzoj1040 内向树DP
查看>>
谈谈Java工程师应该具有的知识
查看>>
记录在Centos下安装和使用Git的过程,从github上克隆仓库和提交。
查看>>
小技巧——优盘图标改变和背景改变
查看>>
异常集合
查看>>
软件工程课程总结
查看>>
JavaScript运算符和控制语句
查看>>
mysql权限管理
查看>>
UVA 12167 Proving Equivalences 强连通分量
查看>>
Jenkins Debian packages
查看>>
如何在Windows XP中设置自定义纸张
查看>>
三星S7562手机拨号时显示“未在网络上注册”是什么原因?
查看>>
熟悉HBase基本操作
查看>>
Flash Mobile Developing Android and iOS Applications
查看>>
flash sin
查看>>
CCF201604-3 路径解析(100分)
查看>>
HDU1879 继续畅通工程
查看>>
一步一步使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之调整首页显示...
查看>>
初学python之,IDLE安装
查看>>