Spring bean的父类继承



Spring bean的父类继承

配置bean
<bean id=”student”>

<property name=”name”>
<value>如哥</value>
</property>
<property name=”age”>
<value>23</value>
</property>
</bean>
<bean id=”degree” parent=”student”>
<property name=”degree”>
<value>学士</value>
</property>

</bean>
子类调用父类的方法
private static void beaninherit() {
System.out.println(“**************************************”);
ApplicationContext ac=new ClassPathXmlApplicationContext(“com/ru/inherit/beans.xml”);

Degree d=(Degree)ac.getBean(“degree”);

System.out.println(d.getName()+d.getAge());
}

http://blog.sina.com.cn/s/articlelist_2540587351_0_2.html