@Component
public abstract class Person
{
private String name;
private String address;
private int age;
//getter and setter methods
}
@Component
public class Customer extends Person
{
private String custId;
//getter and setter methods
}
public static void main( String[] args )
{
ApplicationContext context =
new ClassPathXmlApplicationContext(new String[] {"Spring-Customer.xml"});
Person person= context.getBean(Customer.class);
}
在这里,我想使用Person类引用来调用Customer类对象。但这给了我编译错误。请让我知道如何使用get bean将抽象类引用分配给子类对象