<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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">
<bean id="helloworld" class="InheritanceBean.HelloWorld"
init-method="init" destroy-method="destroy">
<property name="message1" value="hello world"></property>
<property name="message2" value="hello world2"></property>
</bean>
<bean id="hellochina" class="InheritanceBean.HelloChina" parent="helloworld"
        init-method="init" destroy-method="destroy">
<!-- <property name="message1" value="Hello China!"></property>  -->
<property name="message3" value="Greate China!"></property>
</bean>
</beans>
不知道为什么,去掉了init-method和destroy-method后程序就不会报错了
package InheritanceBean;import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class MainApp { public static void main(String[] args) {
// TODO Auto-generated method stub
AbstractApplicationContext context=new ClassPathXmlApplicationContext("InheritanceBean/MyXml.xml");

HelloWorld objA=(HelloWorld)context.getBean("helloworld");
objA.getMessage1();
objA.getMessage2();

HelloChina objB=(HelloChina)context.getBean("hellochina");

objB.getMessage1();
objB.getMessage2();
objB.getMessage3(); context.registerShutdownHook();

}}