如何使用Spring Get bean将父级引用分配给子对象

时间:2019-04-23 12:53:19

标签: java spring

@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将抽象类引用分配给子类对象

0 个答案:

没有答案