Spring-bean Definition Inheritance

Source: Internet
Author: User

A bean definition can contain a lot of configuration information, including constructor arguments, property values, and Co Ntainer-specific information such as initialization method, static factory method name, and so on.

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

Spring Bean definition inheritance have nothing to do with Java class inheritance but the inheritance concept is same. You can define a parent bean definition as a template and other child beans can inherit the required configuration from th E Parent Bean.

When you use xml-based configuration metadata, you indicate a child bean definition by using the parent attribute , specifying the parent bean as the value of this attribute.

<?XML version = "1.0" encoding = "UTF-8"?><Beansxmlns= "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-3.0.xsd ">   <BeanID= "Beanteamplate"Abstract= "true">      < Propertyname= "Message1"value= "Hello world!"/>      < Propertyname= "Message2"value= "Hello Second world!"/>      < Propertyname= "Message3"value= "Namaste india!"/>   </Bean>   <BeanID= "Helloindia"class= "Com.tutorialspoint.HelloIndia"Parent= "Beanteamplate">      < Propertyname= "Message1"value= "Hello india!"/>      < Propertyname= "Message3"value= "Namaste india!"/>   </Bean>   </Beans>
View Code

Spring-bean Definition Inheritance

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.