前言
作为Spring 框架中核心,bean标签具有多个属性。其中parent属性具有一些很有意思的使用之处,本文将以实例介绍相关情况。
1、parent属性基本介绍
1.1.官方介绍
对于bean标签的相关使用,spring框架将之存放在spring-beans-XXX.jar中以下两个文件中:
- spring-beans.dtd (相对路径org\springframework\beans\factory\xml\spring-beans.dtd)
- spring-beans.xsd(相对路径org\springframework\beans\factory\xml\ spring-beans.xsd)
其中,在 spring-beans.dtd 中对parent属性有如下介绍
Optionally specify a parent bean definition.
Will use the bean class of the parent if none specified, but can
also override it. In the latter case, the child bean class must be
compatible with the parent, i.e. accept the parent's property values
and constructor argument values, if any.
A child bean definition will inherit constructor argument values,
property values and