Bean definition reuse involves two steps:
1. Define a parent bean.
2. Make the child bean inherit the parent bean and add its own property.
The definition of a parent bean is generally as follows:
<Bean name = "templatebean" class = "com. ronglei. test. reusebean "abstract =" true "> <property name =" beantype "value =" testbeantype "/> </bean>
The bean label abstract attribute is defined as true, so that this bean cannot be instantiated and can only be used as a template.
To use this parent bean template as a child bean, you only need to use the parent attribute of the bean tag for reference, as shown below:
<Bean name = "instancebean" parent = "templatebean"> <property name = "beanid" value = "1"/> </bean>
The definition is very simple. The child bean actually inherits from the parent Bean:
Constructor parameter, property value, method override, init method definition, destory method definition, factory method definition
The following content is not inherited:
Depends-on definition, autowire definition, dependency-check definition, scope definition, lazy-init Definition
It still means that the child bean inherits the attributes and method parameters from the parent bean, but does not inherit the attributes and behavior modification definitions of the bean.