【Basic computer】-----Bean Definition Inheritance_何新生-功夫熊猫的博客-程序员宅基地

技术标签: $【总结人生】  spring  $【基础积累】  parent  ----------【计算机路】  UML  spingMVC  javabean  $【Java】  



                      Bean Definition Inheritance


      What is that mean?inheritance,the bean definition can contain a lot of configuration information, including constructor arguments, property values, and container-specific information such as initialization method, static factory method name, and so on.

    A child bean definition inherits configuration data from a parent definition. The child definition can override some values, or add others, as needed.
   
 

Here is the UML】:
 


Code of bean  of the first time: So,here you can see  the repeation is bad taste: 

                   
 

We want to make it better, So, how to deal this problem?Here is the content of bean.xml file:


<?xml version="1.0" encoding="UTF-8"?>
<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.xsd">
        
        <bean id="abstractStudent" class="com.tgb.Student" abstract="true">
            <property name="className" value="classFive"></property>
        </bean>
        
        <bean id="zhangsan" parent="abstractStudent">
        </bean>
         <bean id="lisi" parent="abstractStudent">
        </bean>
         <bean id="wangwu" parent="abstractStudent">
        </bean>
</beans>  



Following is the content of the Student.java file:

 package com.tgb;
public class Student {
    private String className;
    public String getClassName() {
        return className;
    }
    public void setClassName(String className) {
        this.className = className;
    }
    @Override
    public String toString() {
        return "Student [className=" + className + "]";
    }
    
}


Here is the Client.java file:
  
package com.tgb;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;




public class Client {
	public static void main(String[] args){
		ApplicationContext ac=new ClassPathXmlApplicationContext("bean.xml");
		
		Student Daniel=(Student)ac.getBean("Daniel");
		System.out.println(Daniel);
		
		Student zhangsan=(Student)ac.getBean("zhangsan");
		System.out.println(zhangsan);
		
		Student lisi=(Student)ac.getBean("lisi");
		System.out.println(lisi);
	}
}




   Once you are done with creating source and bean configuration files, let us run the application. If everything is fine with your application, this will print the following message:

                 
 


    The parent bean cannot be instantiated on its own because it is incomplete, and it is also explicitly marked as abstract. When a definition is abstract like this, it is usable only as a pure template bean definition that serves as a parent definition for child definitions.



版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u013067756/article/details/52040350

智能推荐

@deprecated 注解的使用_tangyiss的博客-程序员宅基地

一、作用用 @Deprecated注解的程序元素,不鼓励程序员使用这样的元素,通常是因为它很危险或存在更好的选择。在使用不被赞成的程序元素或在不被赞成的代码中执行重写时,编译器会发出警告。二、传递性如果一个类被使用了@Deprecated注解,在调用这个类的地方IDE会给出提示。但如果调用这个类的字类IDE会进行提示吗?/** * @author tangyi * ...

c_select 调用参数说明_weixin_30698297的博客-程序员宅基地

c_select 调用1. select系统调用select系统调用是用来让我们的程序监视多个文件描述符的状态变化的。程序会停在select这里等待,直到被监视的文件描述符有某一个或多个发生了状态改变。select()的机制中提供一fd_set的数据结构,实际上是一long类型的数组,每一个数组元素都能与一打开的文件句柄建立联系,建立联系的工作由程序员完成,当调用select()时,由内核根据...

Python课程-程序员宅基地

Python课程p1 爬虫简介通过编写程序,模拟浏览器上网,然后让其去互联网抓取数据的过程.爬虫的价值:p2 爬虫的合法性探究p3 爬虫初始深入抓取页面爬虫在使用场景中的分类:爬虫中的矛与盾反爬机制门户网站,可以通过制定相关策略或者技术手段,防止爬虫程序进行网站数据的爬取。反反爬策略 爬虫程序可以通过制定相关的策略或者技术手段,破解门户网站中具备的反爬机制,从而可以获得门户网站信息。 robots.txt协议 君子协议。规定了网站中哪些数据可以被爬

python机器学习第四章:数据预处理——构建好的训练数据集_乐乐大鱼塘的博客-程序员宅基地

1、缺失数据的处理知识点1:通过dropna方法将存在缺失值的特征或者样本删除#remove rows that contain missing values df.dropna(axis=0) #remove columns that contain missing values df.dropna(axis=1)#only drop rows where all columns ...

2014-04-03研究笔记整理_weixin_33920401的博客-程序员宅基地

利用cca进行fmri分析在肖柯的硕士毕业论文中《基于CCA的fMRI时空模型数据处理方法的研究》,他的总体思路是利用cca提取出fmri图像在时间和空间上两个相关系数,也就是两个特征,然后利用pca,对这两个特征进行融合,得的一个综合的相关系数,然后利用这个综合的相关系数进行选取阈值,然后判别激活与否。首先,他没有降噪。其次,他有一个假设,就...

Uniapp_HBuilderX打包app_hbuidx打包app版本号_会做梦的辣条鱼的博客-程序员宅基地

Uniapp HBuilderX 打包app一,项目启动(1).创建打包文件:文件》新建》项目(2).选择:5+App》修改项目名称》修改地址》点击创建二.运行打包项目,将生成的页面及css,js等相关文件,填充在刚刚已经创建好的空打包文件中:三,右键点击manifest.json进行文件配置:(1).注册DCould账号,获取DCould_AppID修改相关应用名称,应用版本名称,应用版本号。(2),勾选允许x86(3)修改app的图标四,打包Android app(

随便推点

Python_杨辉三角-金字塔版_瑞 新的博客-程序员宅基地

#杨辉三角-金字塔版'''注意:迭代对象1金字塔的数字列表2列表数值转str类型.center居中'''def triangle(): N = [1] while True: yield N # generator特点在于:在执行过程中,遇到yield就中断,下次又继续执行 L = N.copy() # 我们需要吧N复制给L,而不能...

Meterphere安装及使用_metersphere安装使用_源哥学的博客-程序员宅基地

MeterPhere安装1、打开Xshell 5 ,输入ssh IP地址连接操作系统2、输入用户名和密码后连接虚拟机3、输入ping IP地址,检测一下系统是否可以访问外网,如果能ping通外网IP说明可以访问4、输入curl -sSL https://github地址/metersphere/metersphere/releases/latest/download/quick_start.sh | sh 开始在线安装5、等待在线安装结束,安装成功6、打开浏览器,访问http://IP地址:80

JAVA-G1垃圾回收器介绍_中年油泥大叔-vick的博客-程序员宅基地

一、概述  G1垃圾回收器是在Java7 update 4之后引入的一个新的垃圾回收器。G1是一个分代的,增量的,并行与并发的标记-复制垃圾回收器。它的设计目标是为了适应现在不断扩大的内存和不断增加的处理器数量,进一步降低暂停时间(pause time),同时兼顾良好的吞吐量。G1回收器和CMS比起来,有以下不同:G1垃圾回收器是compacting的,因此其回收得到的空间是连续的。这避免了CMS回收器因为不连续空间所造成的问题。如需要更大的堆空间,更多的floating garbage。连续空间意味

ubuntu 18.04 +anconda+spyder+tensorflow_哈哈哈,冲冲冲的博客-程序员宅基地

[email protected]:~$ cd [email protected]:~/Desktop$ bash Anaconda3-5.2.0-Linux-x86_64.shWelcome to Anaconda3 5.2.0In order to c...

杰里之AD697N/AC897N 加强 ESD 静电防护措施说明【篇】_Rambo-Lamborghini的博客-程序员宅基地

一、方案设计原理图设计、PCB layout。方案规划的目标(产品、PCBA)必须满足接触 ESD≧±4K 和空气 ESD≧±8K。原理图和 PCB 上需对天线进行保护,有以下措施:1、原理图上 RF 天线优先选择“双极性或 PIFA”天线。2、靠近天线端添加双向 TVS 管(如图 3),且双向 TVS 管至少要满足图 4 特性,表 1 提供 3 种双向 TVS管型号,(双极性或 PIFA 天线方案可根据产品实测的静电能力,满足目标的可 NC)。...

利用SQOOP将数据从数据库导入到HDFS_Omnipotent-Youth的博客-程序员宅基地

#Oracle的连接字符串,其中包含了Oracle的地址,SID,和端口号CONNECTURL=jdbc:oracle:thin:@20.135.60.21:1521:DWRAC2#使用的用户名ORACLENAME=kkaa#使用的密码ORACLEPASSWORD=kkaa123#需要从Oracle中导入的表名oralceTableName=

推荐文章

热门文章

相关标签