如何在子类中注入在父类中定义的bean?

时间:2018-07-09 21:45:53

标签: java spring spring-mvc dependency-injection javabeans

我想注入在子类的父类中定义的bean。 父母

abstract class ParentService
{
    private ParentDao parentDao;
    public void foo()
    {
        parentDao.doStuff();
    }
}

<bean id="parentService" class="core.sample.ParentService" abstract="true">
</bean>

class ChildService1 extends ParentService
{
    //This calls childDao1. 
    //what goes here?
}

class ChildService2 extends ParentService
{
    //This calls childDao2.
    //what goes here?
}

<bean id="childDao1" class="core.sample.ChildDao1">
</bean>
<bean id="ChildDao2" class="core.sample.ChildDao2">
</bean>

ChildDao1 ChildDao2 ParentDao 的子类。

另外,请提出如何将泛型用于同一用途。

0 个答案:

没有答案