"Bean inheritance" abstract beans in spring and bean inheritance

Source: Internet
Author: User

Declare a bean as an abstract bean by specifying abstract= "true", which can be inherited;
  
 
  1. <?xml version="1.0" encoding="GBK"?>
  2. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
  6. <!-- 定义Axe实例 -->
  7. <bean id="steelAxe" class="org.crazyit.app.service.impl.SteelAxe"/>
  8. <!-- 指定abstract="true"定义抽象Bean -->
  9. <bean id="personTemplate" abstract="true">
  10. <property name="name" value="crazyit"/>
  11. <property name="axe" ref="steelAxe"/>
  12. </bean>
  13. <!-- 通过指定parent属性指定下面Bean配置可从父Bean继承得到配置信息 -->
  14. <bean id="chinese" class="org.crazyit.app.service.impl.Chinese"
  15. parent="personTemplate"/>
  16. <bean id="american" class="org.crazyit.app.service.impl.American"
  17. parent="personTemplate"/>
  18. </beans>
The above configuration is equivalent to the following
  
 
  1. <?xml version="1.0" encoding="GBK"?>
  2. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
  6. <!-- 定义Axe实例 -->
  7. <bean id="steelAxe" class="org.crazyit.app.service.impl.SteelAxe"/>
  8. <!--Specify the following bean configuration from the parent bean by specifying the parent property to inherit the configuration information--
  9. span class= "tag" ><bean id = Span class= "ATV" > "Chinese" class = "Org.crazyit.app.service.impl.Chinese";
  10. <property name="name" value="crazyit"/> <property name="axe" ref="steelAxe"/>
  11. <bean/>

  12. <bean id="american" class="org.crazyit.app.service.impl.American">
  13. < Span class= "ATV" > <property Name = "name" value = "Crazyit" /> <property name = "axe" ref = "Steelaxe" /> <bean />
  14. </beans>





From for notes (Wiz)

"Bean inheritance" abstract beans in spring and bean 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.