日期:2014-05-19  浏览次数:20601 次

子类如何使用spring完成父类的初始化
使用Spring来完成类的实例化
<bean id="SuperAction" class="com.SuperAction" scope="prototype">
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
</bean>

<bean id="SubAction1" class="com.SubAction1" scope="prototype">
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
</bean>

<bean id="SubAction2" class="com.SubAction2" scope="prototype">
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
</bean>
类SubAction1和类SubAction2都继承类SuperAction,如果有多个类都继承SupAction
那么每个子类都需要配置
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
有什么方法可以不用在每个子类中都进行配置

------解决方案--------------------
XML code

    <bean name="LogTestService" class="com.study.spring.aop.service.impl.LogTestServiceImpl"></bean>
    
    <bean name="superObject" class="com.study.spring.aop.SuperObject">
        <property name="logTestService" ref="LogTestService"></property>
    </bean>
    
    <bean name="subObject" class="com.study.spring.aop.SubObject" parent="superObject"></bean>