Spring study notes about Bean definition reuse-use abstract and parent label attributes

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.